Skip to content

Commit 476d43c

Browse files
committed
Hide Latex Source after evaluated, show only the output part
1 parent 3b86f9e commit 476d43c

File tree

6 files changed

+105
-53
lines changed

6 files changed

+105
-53
lines changed

OMNotebook/OMNotebookGUI/cellcommands.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,20 @@ namespace IAEX
433433

434434
newLatexCell->setStyle( style );
435435
newLatexCell->setText( oldLatexCell->text() );
436-
437436
if( oldLatexCell->isEvaluated() )
438437
{
439-
newLatexCell->setEvaluated( true );
438+
newLatexCell->setEvaluated(true);
440439
//newLatexCell->setTextOutput( oldLatexCell->textOutput() );
441440
newLatexCell->setTextOutputHtml(oldLatexCell->textOutputHtml());
441+
newLatexCell->output_->show();
442+
newLatexCell->latexButton->show();
442443
}
443444
else
444-
newLatexCell->setEvaluated( false );
445+
{
446+
newLatexCell->setEvaluated(false);
447+
}
448+
//newLatexCell->setClosed( oldLatexCell->isClosed() );
445449

446-
newLatexCell->setClosed( oldLatexCell->isClosed() );
447450
}
448451

449452
else if( typeid(TextCell) == typeid( *newCell ))

OMNotebook/OMNotebookGUI/celldocument.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ namespace IAEX
945945
*/
946946
void CellDocument::mouseClickedOnCell(Cell *clickedCell)
947947
{
948+
948949
// 2006-04-25, AF
949950
if( lastClickedCell_ == clickedCell )
950951
return;
@@ -978,7 +979,6 @@ namespace IAEX
978979

979980
clickedCell->setReadOnly(false);
980981
clickedCell->setFocus(true);
981-
982982
emit cursorChanged();
983983
}
984984

@@ -1026,6 +1026,20 @@ namespace IAEX
10261026
graphcell->setFocusOutput(true);
10271027
}
10281028

1029+
else if(typeid(LatexCell) == typeid(*clickedCell))
1030+
{
1031+
LatexCell *latexcell = dynamic_cast<LatexCell*>(clickedCell);
1032+
latexcell->setReadOnly(false);
1033+
latexcell->setFocusOutput(true);
1034+
/* QString text=latexcell->textOutput();
1035+
if(!text.isEmpty())
1036+
{
1037+
latexcell->output_->hide();
1038+
latexcell->input_->show();
1039+
latexcell->hideButton->show();
1040+
} */
1041+
}
1042+
10291043
else
10301044
{
10311045
clickedCell->setReadOnly(false);

OMNotebook/OMNotebookGUI/latexcell.cpp

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ namespace IAEX {
105105
};
106106

107107

108-
109108
/*!
110-
* \class MyTextEdit2
111-
* \author Anders Ferström
112-
* \date 2005-11-01
113-
*
114109
* \brief Extends QTextEdit. Mostly so I can catch when a user
115110
* clicks on the editor
116111
*/
@@ -183,7 +178,6 @@ namespace IAEX {
183178
*/
184179
void MyTextEdit3::keyPressEvent(QKeyEvent *event )
185180
{
186-
emit showVariableButton(false);
187181
// EVAL, key: SHIFT + RETURN || SHIFT + ENTER
188182
if( event->modifiers() == Qt::ShiftModifier &&
189183
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) )
@@ -483,7 +477,7 @@ namespace IAEX {
483477
createLatexCell();
484478
createOutputCell();
485479

486-
connect(input_, SIGNAL(showVariableButton(bool)), this, SLOT(showVariableButton(bool)));
480+
//connect(input_, SIGNAL(showVariableButton(bool)), this, SLOT(showVariableButton(bool)));
487481

488482
//connect(output_, SIGNAL(anchorClicked(const QUrl&)), input_, SLOT(goToPos(const QUrl&)));
489483

@@ -526,12 +520,13 @@ namespace IAEX {
526520
{
527521

528522
input_ = new MyTextEdit3( mainWidget() );
529-
variableButton = new QPushButton("D",input_);
530-
variableButton->setToolTip("New simulation data available");
531-
variableButton->setMaximumWidth(25);
523+
hideButton = new QPushButton("H",input_);
524+
hideButton->setToolTip("Hide the Latex Source");
525+
hideButton->setMaximumWidth(25);
532526
layout_->addWidget( input_, 1, 1 );
533-
layout_->addWidget(variableButton, 1, 2);
534-
variableButton->hide();
527+
layout_->addWidget(hideButton, 1, 2,Qt::AlignTop);
528+
529+
hideButton->hide();
535530
// 2006-03-02 AF, Add a chapter counter
536531
createChapterCounter();
537532

@@ -551,18 +546,20 @@ namespace IAEX {
551546

552547
input_->setPalette(palette);
553548

554-
variableButton->setPalette(palette);
549+
hideButton->setPalette(palette);
555550
// is this needed, don't know /AF
556551
input_->installEventFilter(this);
557-
558-
connect( input_, SIGNAL( textChanged() ), this, SLOT( contentChanged() ));
552+
connect(hideButton, SIGNAL(clicked()), this, SLOT(hidelatexsource()));
553+
connect( input_, SIGNAL( textChanged() ), this, SLOT( contentChanged()));
559554
connect( input_, SIGNAL( clickOnCell() ), this, SLOT( clickEvent() ));
560555
connect( input_, SIGNAL( wheelMove(QWheelEvent*) ), this, SLOT( wheelEvent(QWheelEvent*) ));
561556
connect( input_, SIGNAL( eval() ), this, SLOT( eval() ));
562557
connect( input_, SIGNAL( command() ), this, SLOT( command() ));
563558
connect( input_, SIGNAL( nextCommand() ), this, SLOT( nextCommand() ));
564559
connect( input_, SIGNAL( nextField() ), this, SLOT( nextField() ));
565-
// connect( input_, SIGNAL( textChanged() ), this, SLOT( addToHighlighter() ));
560+
connect( input_, SIGNAL( nextField() ), this, SLOT( nextField() ));
561+
562+
// connect( input_, SIGNAL( textChanged() ), this, SLOT( addToHighlighter() ));
566563
connect( input_, SIGNAL( currentCharFormatChanged(const QTextCharFormat &) ),
567564
this, SLOT( charFormatChanged(const QTextCharFormat &) ));
568565
connect( input_, SIGNAL( forwardAction(int) ), this, SIGNAL( forwardAction(int) ));
@@ -574,13 +571,21 @@ namespace IAEX {
574571
connect(input_, SIGNAL(textChanged()), input_, SLOT(setModified()));
575572
}
576573

577-
void LatexCell::showVariableButton(bool b)
578-
{
579-
if(b)
580-
variableButton->show();
581-
else
582-
variableButton->hide();
583-
}
574+
void LatexCell::hidelatexsource()
575+
{
576+
input_->hide();
577+
hideButton->hide();
578+
latexButton->show();
579+
output_->show();
580+
}
581+
582+
void LatexCell::showlatexsource()
583+
{
584+
output_->hide();
585+
hideButton->show();
586+
latexButton->hide();
587+
input_->show();
588+
}
584589

585590
/*!
586591
* \brief Creates the QTextEdit for the output part of the
@@ -590,8 +595,12 @@ namespace IAEX {
590595
void LatexCell::createOutputCell()
591596
{
592597
output_ = new MyTextEdit3( mainWidget() );
593-
layout_->addWidget( output_, 2, 1 );
594-
598+
layout_->addWidget( output_, 1, 1 );
599+
latexButton = new QPushButton("L",output_);
600+
latexButton->setToolTip("Show the Latex Source");
601+
latexButton->setMaximumWidth(25);
602+
layout_->addWidget( latexButton, 1, 2, Qt::AlignTop);
603+
latexButton->hide();
595604
output_->setReadOnly( true );
596605

597606
output_->setOpenLinks(false);
@@ -601,7 +610,7 @@ namespace IAEX {
601610

602611
output_->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
603612
output_->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
604-
613+
connect(latexButton, SIGNAL(clicked()), this, SLOT(showlatexsource()));
605614
connect( output_, SIGNAL( textChanged() ), this, SLOT(contentChanged()));
606615
connect( output_, SIGNAL( clickOnCell() ), this, SLOT( clickEventOutput() ));
607616
connect( output_, SIGNAL( wheelMove(QWheelEvent*) ), this, SLOT( wheelEvent(QWheelEvent*) ));
@@ -1149,7 +1158,8 @@ void LatexCell::eval()
11491158
* 4) Display the output as image to the output cell inorder to maintain the
11501159
* equations and formula structures
11511160
*/
1152-
1161+
//hideButton->hide();
1162+
//latexButton->show();
11531163
input_->blockSignals(true);
11541164
output_->blockSignals(true);
11551165
output_->textCursor().insertText("");
@@ -1193,14 +1203,13 @@ void LatexCell::eval()
11931203
/* Check for latex is installed */
11941204
if (Latexversion.isEmpty())
11951205
{
1196-
//qDebug()<< "Latex is not installed in your system";
1197-
output_->clear();
1198-
output_->textCursor().insertText("Error: Latex is not installed in your System");
1199-
setClosed(false);
1206+
QMessageBox::warning( 0, "Error", "Latex is not installed in your System, This cell cannot be evaluated", "OK" );
12001207
}
12011208
/*Generate the DVI file from tex through latex */
12021209
if (!Latexversion.isEmpty())
12031210
{
1211+
hideButton->hide();
1212+
latexButton->show();
12041213
process->start("latex", QStringList() << "-halt-on-error" << Tex);
12051214
process->waitForFinished();
12061215
QFile logfile(log);
@@ -1244,30 +1253,35 @@ void LatexCell::eval()
12441253
QFileInfo checkpng(Png);
12451254
if(!checkpng.exists())
12461255
{
1256+
output_->clear();
12471257
output_->textCursor().insertText("Error:Problem in finding dvipng executable");
12481258
setClosed(false);
1259+
12491260
}
12501261
else
12511262
{
12521263
output_->clear();
12531264
output_->textCursor().insertImage(Png);
1254-
setClosed(false);
1265+
//setClosed(false);
1266+
input_->hide();
1267+
output_->show();
1268+
12551269
}
12561270
}
12571271
else
12581272
{
1259-
output_->clear();
1260-
output_->textCursor().insertText("Message:Maximum of 1 page document generation is supported per Latexcell, The script generates more than 1 page, Add a new Latex cell and create the document");
1261-
setClosed(false);
12621273

1274+
QMessageBox::warning( 0, "Warning", "Maximum of 1 page document generation is supported per Latexcell, The script generates more than 1 page", "OK" );
12631275
}
12641276
}
12651277
}
12661278
else
12671279
{
12681280
//qDebug()<< "Empty cells can't be evaluated";
1281+
hideButton->hide();
1282+
latexButton->show();
12691283
output_->clear();
1270-
output_->textCursor().insertText("Message: Empty Cells cannot be Evaluated");
1284+
output_->textCursor().insertText("Message: Empty Latex Cells cannot be Evaluated");
12711285
setClosed(false);
12721286
}
12731287
input_->blockSignals(false);

OMNotebook/OMNotebookGUI/latexcell.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ namespace IAEX
9696

9797
public slots:
9898
void eval();
99+
void hidelatexsource();
100+
void showlatexsource();
99101
void command();
100102
void nextCommand();
101103
void nextField();
@@ -117,7 +119,7 @@ namespace IAEX
117119
virtual void setFocus(const bool focus);
118120
virtual void setFocusOutput(const bool focus);
119121
void setExpr(QString);
120-
void showVariableButton(bool);
122+
//void showVariableButton(bool);
121123
void setState(int state);
122124

123125
protected:
@@ -149,7 +151,10 @@ namespace IAEX
149151
Document *document_;
150152

151153
public:
152-
QPushButton* variableButton;
154+
//QPushButton* variableButton;
155+
QPushButton* hideButton;
156+
QPushButton* latexButton;
157+
153158
QTemporaryFile* imageFile;
154159
};
155160

@@ -184,7 +189,7 @@ namespace IAEX
184189
void forwardAction( int );
185190
void updatePos(int, int);
186191
void setState(int);
187-
void showVariableButton(bool);
192+
//void showVariableButton(bool);
188193

189194
protected:
190195
void mousePressEvent(QMouseEvent *event);

OMNotebook/OMNotebookGUI/notebook.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,10 +4092,13 @@ void NotebookWindow::shiftcellsUp()
40924092
subject_->cursorStepUp();
40934093
subject_->executeCommand(new CreateNewCellCommand("Latex"));
40944094
LatexCell *newcell = dynamic_cast<LatexCell *>(subject_->getCursor()->currentCell());
4095-
newcell->setEvaluated(true);
4096-
newcell->setClosed(false);
4095+
//newcell->setEvaluated(true);
4096+
// newcell->setClosed(false);
40974097
newcell->setText(latexinput);
40984098
newcell->setTextOutputHtml(latexoutput);
4099+
newcell->input_->hide();
4100+
newcell->output_->show();
4101+
newcell->latexButton->show();
40994102
}
41004103
else
41014104
{
@@ -4211,10 +4214,13 @@ void NotebookWindow::shiftcellsDown()
42114214
subject_->cursorStepDown();
42124215
subject_->executeCommand(new CreateNewCellCommand("Latex"));
42134216
LatexCell *newcell_d = dynamic_cast<LatexCell *>(subject_->getCursor()->currentCell());
4214-
newcell_d->setEvaluated(true);
4215-
newcell_d->setClosed(false);
4217+
//newcell_d->setEvaluated(true);
4218+
//newcell_d->setClosed(false);
42164219
newcell_d->setText(latexinput_d);
42174220
newcell_d->setTextOutputHtml(latexoutput_d);
4221+
newcell_d->input_->hide();
4222+
newcell_d->output_->show();
4223+
newcell_d->latexButton->show();
42184224
}
42194225
else
42204226
{
@@ -4266,10 +4272,10 @@ void NotebookWindow::evalall()
42664272
g->eval();
42674273
}
42684274

4269-
if(LatexCell *g = dynamic_cast<LatexCell*>(cellcount[i]))
4275+
/* if(LatexCell *g = dynamic_cast<LatexCell*>(cellcount[i]))
42704276
{
42714277
g->eval();
4272-
}
4278+
} */
42734279

42744280

42754281
if(InputCell *g = dynamic_cast<InputCell*>(cellcount[i]))

OMNotebook/OMNotebookGUI/xmlparser.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,15 @@ namespace IAEX
737737
{
738738
LatexCell *iCell = dynamic_cast<LatexCell*>(latexcell);
739739
iCell->setTextOutput( e.text() );
740+
if(!e.text().isEmpty())
741+
{
742+
iCell->output_->show();
743+
iCell->latexButton->show();
744+
}
745+
else
746+
{
747+
iCell->input_->show();
748+
}
740749
}
741750
else if( e.tagName() == XML_IMAGE )
742751
{
@@ -763,19 +772,18 @@ namespace IAEX
763772

764773
// graphcell->setText( text ); //fjass
765774

766-
LatexCell *gCell = dynamic_cast<LatexCell*>(latexcell);
775+
/* LatexCell *gCell = dynamic_cast<LatexCell*>(latexcell);
767776
768777
QString closed = element.attribute( XML_CLOSED, XML_FALSE );
769778
if( closed == XML_TRUE )
770779
gCell->setClosed( true,true );
771780
else if( closed == XML_FALSE )
772781
gCell->setClosed( false,true );
773782
else
774-
throw runtime_error( "Unknown closed value in latexcell" );
783+
throw runtime_error( "Unknown closed value in latexcell" ); */
775784

776785
parent->addChild(latexcell);
777786

778-
779787
}
780788

781789

@@ -851,6 +859,8 @@ namespace IAEX
851859

852860
latexcell->setTextOutputHtml( html );
853861
latexcell->output_->textCursor().insertImage(newname);
862+
latexcell->output_->show();
863+
latexcell->latexButton->show();
854864
}
855865

856866
else

0 commit comments

Comments
 (0)