Skip to content

Commit

Permalink
improve the evaluation of latexcells, automatic hiding of latex sourc…
Browse files Browse the repository at this point in the history
…e and height adjustments
  • Loading branch information
arun3688 committed Oct 8, 2015
1 parent 6302217 commit e90ff37
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 104 deletions.
7 changes: 3 additions & 4 deletions OMNotebook/OMNotebookGUI/cellcommands.cpp
Expand Up @@ -436,20 +436,19 @@ namespace IAEX
LatexCell *oldLatexCell = dynamic_cast<LatexCell *>( cell );

newLatexCell->setStyle( style );
newLatexCell->setText( oldLatexCell->text() );
newLatexCell->setTextHtml(oldLatexCell->textHtml());
if( oldLatexCell->isEvaluated() )
{
newLatexCell->setEvaluated(true);
//newLatexCell->setTextOutput( oldLatexCell->textOutput() );
newLatexCell->setTextOutputHtml(oldLatexCell->textOutputHtml());
newLatexCell->output_->show();
newLatexCell->latexButton->show();

}
else
{
newLatexCell->setEvaluated(false);
}
//newLatexCell->setClosed( oldLatexCell->isClosed() );
newLatexCell->setClosed( oldLatexCell->isClosed() );

}

Expand Down
21 changes: 20 additions & 1 deletion OMNotebook/OMNotebookGUI/celldocument.cpp
Expand Up @@ -977,9 +977,27 @@ namespace IAEX
getCursor()->moveAfter(clickedCell); //Results in bus error why?
}

if( typeid(LatexCell) == typeid(*clickedCell))
{
LatexCell *latexcell = dynamic_cast<LatexCell*>(clickedCell);
bool r =latexcell->isEvaluated();
if(r==true)
{
latexcell->input_->setReadOnly(true);
latexcell->setFocus(true);
}
else
{
latexcell->input_->setReadOnly(false);
}
}
else
{
clickedCell->setReadOnly(false);
clickedCell->setFocus(true);
}
emit cursorChanged();

}

/*!
Expand Down Expand Up @@ -1029,8 +1047,9 @@ namespace IAEX
else if(typeid(LatexCell) == typeid(*clickedCell))
{
LatexCell *latexcell = dynamic_cast<LatexCell*>(clickedCell);
latexcell->setReadOnly(false);
//latexcell->setReadOnly(false);
latexcell->setFocusOutput(true);
latexcell->output_->setReadOnly(false);
/* QString text=latexcell->textOutput();
if(!text.isEmpty())
{
Expand Down
5 changes: 5 additions & 0 deletions OMNotebook/OMNotebookGUI/cellfactory.cpp
Expand Up @@ -233,11 +233,16 @@ namespace IAEX
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(text->output_, SIGNAL(undoAvailable(bool)), doc_, SIGNAL(undoAvailable(bool)));
QObject::connect(text->output_, SIGNAL(redoAvailable(bool)), doc_, SIGNAL(redoAvailable(bool)));

// if(CellDocument* d = dynamic_cast<CellDocument*>(doc_))
QObject::connect(doc_, SIGNAL(setAutoIndent(bool)), text->input_, SLOT(setAutoIndent(bool)));
QObject::connect(doc_, SIGNAL(setAutoIndent(bool)), text->output_, SLOT(setAutoIndent(bool)));

//QObject::connect(doc_, SIGNAL(evaluate()), text->input_, SIGNAL(eval()));
text->input_->setAutoIndent(dynamic_cast<CellDocument*>(doc_)->autoIndent);
text->output_->setAutoIndent(dynamic_cast<CellDocument*>(doc_)->autoIndent);

return text;
}
Expand Down
102 changes: 40 additions & 62 deletions OMNotebook/OMNotebookGUI/latexcell.cpp
Expand Up @@ -520,16 +520,8 @@ namespace IAEX {
{

input_ = new MyTextEdit3( mainWidget() );
hideButton = new QPushButton("H",input_);
hideButton->setToolTip("Hide the Latex Source");
hideButton->setMaximumWidth(25);
layout_->addWidget( input_, 1, 1 );
layout_->addWidget(hideButton, 1, 2,Qt::AlignTop);

hideButton->hide();
// 2006-03-02 AF, Add a chapter counter
createChapterCounter();

input_->setReadOnly( true );
input_->setUndoRedoEnabled( true );
input_->setFrameShape( QFrame::Box );
Expand All @@ -543,13 +535,9 @@ namespace IAEX {

// palette.setColor(input_->backgroundRole(), QColor(Qt::lightGray));
palette.setColor(input_->backgroundRole(),QColor(247,247,247));

input_->setPalette(palette);

hideButton->setPalette(palette);
// is this needed, don't know /AF
input_->installEventFilter(this);
connect(hideButton, SIGNAL(clicked()), this, SLOT(hidelatexsource()));
connect( input_, SIGNAL( textChanged() ), this, SLOT( contentChanged()));
connect( input_, SIGNAL( clickOnCell() ), this, SLOT( clickEvent() ));
connect( input_, SIGNAL( wheelMove(QWheelEvent*) ), this, SLOT( wheelEvent(QWheelEvent*) ));
Expand All @@ -559,9 +547,9 @@ namespace IAEX {
connect( input_, SIGNAL( nextField() ), this, SLOT( nextField() ));
connect( input_, SIGNAL( nextField() ), this, SLOT( nextField() ));

// connect( input_, SIGNAL( textChanged() ), this, SLOT( addToHighlighter() ));
//connect( input_, SIGNAL( textChanged() ), this, SLOT( addToHighlighter() ));
connect( input_, SIGNAL( currentCharFormatChanged(const QTextCharFormat &) ),
this, SLOT( charFormatChanged(const QTextCharFormat &) ));
this, SLOT( charFormatChanged(const QTextCharFormat &) ));
connect( input_, SIGNAL( forwardAction(int) ), this, SIGNAL( forwardAction(int) ));

connect( input_, SIGNAL(updatePos(int, int)), this, SIGNAL(updatePos(int, int)));
Expand All @@ -571,22 +559,6 @@ namespace IAEX {
connect(input_, SIGNAL(textChanged()), input_, SLOT(setModified()));
}

void LatexCell::hidelatexsource()
{
input_->hide();
hideButton->hide();
latexButton->show();
output_->show();
}

void LatexCell::showlatexsource()
{
output_->hide();
hideButton->show();
latexButton->hide();
input_->show();
}

/*!
* \brief Creates the QTextEdit for the output part of the
* LatexCell
Expand All @@ -595,27 +567,19 @@ namespace IAEX {
void LatexCell::createOutputCell()
{
output_ = new MyTextEdit3( mainWidget() );
layout_->addWidget( output_, 1, 1 );
latexButton = new QPushButton("L",output_);
latexButton->setToolTip("Show the Latex Source");
latexButton->setMaximumWidth(25);
layout_->addWidget( latexButton, 1, 2, Qt::AlignTop);
latexButton->hide();
layout_->addWidget( output_, 2, 1 );
output_->setReadOnly( true );

output_->setUndoRedoEnabled( true );
output_->setOpenLinks(false);

output_->setFrameShape( QFrame::Box );
output_->setAutoFormatting( QTextEdit::AutoNone );

output_->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
output_->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
connect(latexButton, SIGNAL(clicked()), this, SLOT(showlatexsource()));
connect( output_, SIGNAL( textChanged() ), this, SLOT(contentChanged()));
connect( output_, SIGNAL( clickOnCell() ), this, SLOT( clickEventOutput() ));
connect( output_, SIGNAL( wheelMove(QWheelEvent*) ), this, SLOT( wheelEvent(QWheelEvent*) ));

connect(output_, SIGNAL(forwardAction(int)), this, SIGNAL(forwardAction(int)));
connect(output_, SIGNAL(textChanged()), output_, SLOT(setModified()));

setOutputStyle();

Expand Down Expand Up @@ -1158,12 +1122,32 @@ void LatexCell::eval()
* 4) Display the output as image to the output cell inorder to maintain the
* equations and formula structures
*/
//hideButton->hide();
//latexButton->show();

/*!
* transfer the latex source to output cell and display the final output in
* inputcell to have better view with hiding latex source and also maintain the
* height of the final output to keep the Notebook precise.Any changes made to
* latex source after first evaluation is done from outputcell.
*/

QString expr;
if(!evaluated_)
{
output_->setText(input_->toPlainText());
QString latexexpr=output_->toPlainText();
expr=latexexpr;
}
else
{
QString latexexpr=output_->toPlainText();
expr=latexexpr;
}
//output_->setReadOnly(false);
input_->blockSignals(true);
output_->blockSignals(true);
output_->textCursor().insertText("");
//output_->textCursor().insertText("");
setState(Eval_l);
input_->setReadOnly(true);
bool setdvi=false;
bool setpng=false;
bool setpage=false;
Expand All @@ -1181,7 +1165,7 @@ void LatexCell::eval()
QString Png = tempfname + ".png";
QString log = tempfname + ".log";

QString expr = input_->toPlainText();
//QString expr = input_->toPlainText();
if (!expr.isEmpty())
{
expr.replace("\\begin{document}","\\begin{document} \\thispagestyle{empty}");
Expand All @@ -1208,8 +1192,6 @@ void LatexCell::eval()
/*Generate the DVI file from tex through latex */
if (!Latexversion.isEmpty())
{
hideButton->hide();
latexButton->show();
process->start("latex", QStringList() << "-halt-on-error" << Tex);
process->waitForFinished();
QFile logfile(log);
Expand All @@ -1230,8 +1212,8 @@ void LatexCell::eval()
QFileInfo checkdvi(Dvi);
if(!checkdvi.exists())
{
output_->clear();
output_->textCursor().insertText(texoutput);
input_->clear();
input_->textCursor().insertText(texoutput);
setClosed(false);
}
else
Expand All @@ -1253,19 +1235,16 @@ void LatexCell::eval()
QFileInfo checkpng(Png);
if(!checkpng.exists())
{
output_->clear();
output_->textCursor().insertText("Error:Problem in finding dvipng executable");
input_->clear();
input_->textCursor().insertText("Error:Problem in finding dvipng executable");
setClosed(false);

}
else
{
output_->clear();
output_->textCursor().insertImage(Png);
//setClosed(false);
input_->hide();
output_->show();

input_->clear();
input_->textCursor().insertImage(Png);
setClosed(true);
}
}
else
Expand All @@ -1278,10 +1257,8 @@ void LatexCell::eval()
else
{
//qDebug()<< "Empty cells can't be evaluated";
hideButton->hide();
latexButton->show();
output_->clear();
output_->textCursor().insertText("Message: Empty Latex Cells cannot be Evaluated");
input_->clear();
input_->textCursor().insertText("Message: Empty Latex Cells cannot be Evaluated");
setClosed(false);
}
input_->blockSignals(false);
Expand Down Expand Up @@ -1333,6 +1310,7 @@ void LatexCell::setState(int state_)

if( commandcompletion->nextCommand( cursor ))
input_->setTextCursor( cursor );

}

/*!
Expand All @@ -1345,6 +1323,7 @@ void LatexCell::setState(int state_)

if( commandcompletion->nextField( cursor ))
input_->setTextCursor( cursor );

}


Expand All @@ -1353,7 +1332,6 @@ void LatexCell::setState(int state_)
* cell is empty. This is done because otherwise the style is lost if
* all text is removed inside a cell.
*/

void LatexCell::charFormatChanged(const QTextCharFormat &)
{
input_->blockSignals( true );
Expand Down
10 changes: 4 additions & 6 deletions OMNotebook/OMNotebookGUI/latexcell.h
Expand Up @@ -96,8 +96,6 @@ namespace IAEX

public slots:
void eval();
void hidelatexsource();
void showlatexsource();
void command();
void nextCommand();
void nextField();
Expand Down Expand Up @@ -143,7 +141,8 @@ namespace IAEX

public:
MyTextEdit3* input_;
QTextBrowser *output_;
MyTextEdit3* output_;
//QTextBrowser *output_;
private:
QTextBrowser *chaptercounter_;
//InputCellDelegate *delegate_;
Expand All @@ -152,9 +151,8 @@ namespace IAEX

public:
//QPushButton* variableButton;
QPushButton* hideButton;
QPushButton* latexButton;

//QPushButton* hideButton;
//QPushButton* latexButton;
QTemporaryFile* imageFile;
};

Expand Down
20 changes: 7 additions & 13 deletions OMNotebook/OMNotebookGUI/notebook.cpp
Expand Up @@ -4086,24 +4086,21 @@ void NotebookWindow::shiftcellsUp()
//qDebug()<<"latexcells"<<eval << l->textOutputHtml();
if(eval==true)
{
QString latexinput=l->text();
QString latexinput=l->textHtml();
QString latexoutput=l->textOutputHtml();
subject_->cursorDeleteCell();
subject_->cursorStepUp();
subject_->executeCommand(new CreateNewCellCommand("Latex"));
LatexCell *newcell = dynamic_cast<LatexCell *>(subject_->getCursor()->currentCell());
//newcell->setEvaluated(true);
// newcell->setClosed(false);
newcell->setText(latexinput);
//newcell->setClosed(false);
newcell->setTextHtml(latexinput);
newcell->setTextOutputHtml(latexoutput);
newcell->input_->hide();
newcell->output_->show();
newcell->latexButton->show();
}
else
{
subject_->cursorDeleteCell();
//subject_->getCursor()->moveUp();
//subject_->getCursor()->moveUp();
subject_->cursorStepUp();
subject_->executeCommand(new CreateNewCellCommand("Latex"));
subject_->getCursor()->currentCell()->setText(currenttext);
Expand Down Expand Up @@ -4208,24 +4205,21 @@ void NotebookWindow::shiftcellsDown()
//qDebug()<<"latexcells"<<eval << ld->textOutputHtml();
if(eval==true)
{
QString latexinput_d=ld->text();
QString latexinput_d=ld->textHtml();
QString latexoutput_d=ld->textOutputHtml();
subject_->cursorDeleteCell();
subject_->cursorStepDown();
subject_->executeCommand(new CreateNewCellCommand("Latex"));
LatexCell *newcell_d = dynamic_cast<LatexCell *>(subject_->getCursor()->currentCell());
//newcell_d->setEvaluated(true);
//newcell_d->setClosed(false);
newcell_d->setText(latexinput_d);
newcell_d->setTextHtml(latexinput_d);
newcell_d->setTextOutputHtml(latexoutput_d);
newcell_d->input_->hide();
newcell_d->output_->show();
newcell_d->latexButton->show();
}
else
{
subject_->cursorDeleteCell();
//subject_->getCursor()->moveUp();
//subject_->getCursor()->moveUp();
subject_->cursorStepDown();
subject_->executeCommand(new CreateNewCellCommand("Latex"));
subject_->getCursor()->currentCell()->setText(currenttext);
Expand Down

0 comments on commit e90ff37

Please sign in to comment.