MainWindow Class Reference

#include <MainWindow.hpp>

Collaboration diagram for MainWindow:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 MainWindow ()
 ~MainWindow ()

Protected Member Functions

void closeEvent (QCloseEvent *event)

Private Slots

void newFile ()
void choose ()
void load (const QString &fileName)
void save ()
void saveAs ()
void print ()
void run ()
void pause ()
void resume ()
void stop ()
void aboutff3d ()
void aboutQt ()
void aboutVtk ()

Private Member Functions

void __buildFileTools ()
void __buildEditorTools ()
void __buildActionTools ()
void __buildHelpTools ()

Private Attributes

QPrinter * printer
EditorWindow__editor
QTextEdit * __console
QString filename
FFThread__ffThread


Detailed Description

Definition at line 40 of file MainWindow.hpp.


Constructor & Destructor Documentation

MainWindow::MainWindow (  ) 

Definition at line 211 of file MainWindow.cpp.

References __buildActionTools(), __buildEditorTools(), __buildFileTools(), __buildHelpTools(), __console, __editor, and printer.

00212   : QMainWindow(0),
00213     __ffThread(0)
00214 {
00215     printer = new QPrinter(QPrinter::HighResolution);
00216 
00217     // create and define the central widget
00218     QTabWidget* tabWidget = new QTabWidget(this);
00219 
00220 
00221     __editor = new EditorWindow;
00222     __editor->setFocus();
00223 
00224     setCentralWidget(tabWidget);
00225   
00226     tabWidget->addTab(__editor,tr("Editor"));
00227 
00228     QVTKWidget* graphicWindow = new QVTKWidget;
00229     tabWidget->addTab(graphicWindow, tr("Graphics"));
00230 
00231     vtkRenderer *ren1= vtkRenderer::New();
00232     ren1->SetBackground( 0.1, 0.2, 0.4 );
00233     vtkVectorText* text = vtkVectorText::New();
00234     text->SetText("ff3d");
00235 
00236     vtkPolyDataMapper* textMapper = vtkPolyDataMapper::New();
00237     textMapper->SetInput(text->GetOutput());
00238     vtkLODActor *actor = vtkLODActor::New();
00239     actor->SetMapper(textMapper);
00240     ren1->AddActor( actor );
00241 
00242     graphicWindow->GetRenderWindow()->AddRenderer(ren1);
00243     graphicWindow->GetRenderWindow()->Render();
00244 
00245     // console
00246     QDockWidget* consoleDock = new QDockWidget("console", this);
00247     __console = new QTextEdit;
00248     __console->setReadOnly(true);
00249     __console->setUndoRedoEnabled(false);
00250     consoleDock->setWidget(__console);
00251     this->addDockWidget(Qt::BottomDockWidgetArea, consoleDock);
00252 
00253     // Build menus
00254     this->__buildFileTools();
00255     this->__buildEditorTools();
00256     this->__buildActionTools();
00257 
00258     menuBar()->addSeparator();
00259     
00260     this->__buildHelpTools();
00261 
00262     statusBar()->showMessage(tr("Wellcome to FreeFEM3D"), 2000);
00263 }

Here is the call graph for this function:

MainWindow::~MainWindow (  ) 

Definition at line 266 of file MainWindow.cpp.

References __ffThread, and printer.

00267 {
00268   if (__ffThread !=0) {
00269     delete __ffThread;
00270   } 
00271   delete printer;
00272 }


Member Function Documentation

void MainWindow::closeEvent ( QCloseEvent *  event  )  [protected]

Definition at line 386 of file MainWindow.cpp.

References __editor, and save().

00387 {
00388   if (!__editor->isWindowModified()) {
00389     ce->accept();
00390     return;
00391   }
00392 
00393   switch(QMessageBox::information(this, "FreeFEM3D",
00394                                   "The document has been changed since "
00395                                   "the last save.",
00396                                   "Save Now", "Cancel", "Leave Anyway",
00397                                   0, 1)) {
00398   case 0:
00399     save();
00400     ce->accept();
00401     break;
00402   case 1:
00403   default: // just for sanity
00404     ce->ignore();
00405     break;
00406   case 2:
00407     ce->accept();
00408     break;
00409   }
00410 }

void MainWindow::newFile (  )  [private, slot]

Definition at line 276 of file MainWindow.cpp.

Referenced by __buildFileTools().

00277 {
00278     MainWindow *ed = new MainWindow;
00279     ed->show();
00280 }

void MainWindow::choose (  )  [private, slot]

Definition at line 282 of file MainWindow.cpp.

References filename, and load().

Referenced by __buildFileTools().

00283 {
00284     filename = QFileDialog::getOpenFileName(this);
00285     if (!filename.isEmpty())
00286         load(filename);
00287     else
00288         statusBar()->showMessage("Loading aborted", 2000);
00289 }

void MainWindow::load ( const QString &  fileName  )  [private, slot]

Definition at line 292 of file MainWindow.cpp.

References __editor.

Referenced by choose().

00293 {
00294     QFile f(fileName);
00295     if (!f.open( QIODevice::ReadOnly))
00296         return;
00297 
00298     QTextStream ts(&f);
00299     __editor->setPlainText(ts.readAll());
00300     __editor->setWindowModified(FALSE);
00301     setWindowTitle(fileName);
00302     statusBar()->showMessage("Loaded document " + fileName, 2000);
00303 }

void MainWindow::save (  )  [private, slot]

Definition at line 306 of file MainWindow.cpp.

References __editor, filename, and saveAs().

Referenced by __buildFileTools(), closeEvent(), and saveAs().

00307 {
00308     if (filename.isEmpty()) {
00309         saveAs();
00310         return;
00311     }
00312 
00313     const QString& text = __editor->toPlainText();
00314     QFile f(filename);
00315     if (!f.open(QIODevice::WriteOnly)) {
00316         statusBar()->showMessage(QString("Could not write to %1").arg(filename),
00317                                  2000);
00318         return;
00319     }
00320 
00321     QTextStream t(&f);
00322     t << text;
00323     f.close();
00324 
00325     __editor->setWindowModified(FALSE);
00326 
00327     setWindowTitle(filename);
00328 
00329     statusBar()->showMessage(QString("File %1 saved").arg(filename), 2000);
00330 }

void MainWindow::saveAs (  )  [private, slot]

Definition at line 333 of file MainWindow.cpp.

References filename, and save().

Referenced by __buildFileTools(), and save().

00334 {
00335     QString fn = QFileDialog::getSaveFileName(this);
00336     if (!fn.isEmpty()) {
00337         filename = fn;
00338         save();
00339     } else {
00340         statusBar()->showMessage("Saving aborted", 2000);
00341     }
00342 }

void MainWindow::print (  )  [private, slot]

Definition at line 345 of file MainWindow.cpp.

References fferr(), and printer.

Referenced by __buildFileTools().

00346 {
00347   printer->setFullPage(TRUE);
00348   statusBar()->showMessage("Printing...");
00349   QPainter p;
00350   if(!p.begin(printer)) {               // paint on printer
00351     statusBar()->showMessage("Printing aborted", 2000);
00352     return;
00353   }
00354   fferr(1) << __FILE__ << ':' << __LINE__ << ": Not implemented\n";
00355 //      QPaintDeviceMetrics metrics(p.device());
00356 //      int dpiy = metrics.logicalDpiY();
00357 //      int margin = (int) ((2/2.54)*dpiy); // 2 cm margins
00358 //      QRect body(margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin);
00359 //      QSimpleRichText richText(QStyleSheet::convertFromPlainText(editor->text()),
00360 //                                QFont(),
00361 //                                editor->context(),
00362 //                                editor->styleSheet(),
00363 //                                editor->mimeSourceFactory(),
00364 //                                body.height());
00365 //      richText.setWidth(&p, body.width());
00366 //      QRect view(body);
00367 //      int page = 1;
00368 //      do {
00369 //          richText.draw(&p, body.left(), body.top(), view, colorGroup());
00370 //          view.moveBy(0, body.height());
00371 //          p.translate(0, -body.height());
00372 //          p.drawText(view.right() - p.fontMetrics().width(QString::number(page)),
00373 //                      view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page));
00374 //          if (view.top()  >= richText.height())
00375 //              break;
00376 //          printer->newPage();
00377 //          page++;
00378 //      } while (TRUE);
00379 
00380 //      statusBar()->showMessage("Printing completed", 2000);
00381 //     } else {
00382 //      statusBar()->showMessage("Printing aborted", 2000);
00383 //     }
00384 }

void MainWindow::run (  )  [private, slot]

Definition at line 413 of file MainWindow.cpp.

References __console, __editor, __ffThread, FFThread::setInput(), and Thread::start().

Referenced by __buildActionTools().

00414 {
00415   std::stringstream text;
00416   text << __editor->toPlainText().toAscii().constData() << std::ends;
00417 
00418   QTextCharFormat defaultFormat;
00419   defaultFormat.setFontFamily("Courier New");
00420   defaultFormat.setFontPointSize(8);
00421 
00422   __console->mergeCurrentCharFormat(defaultFormat);
00423   __console->append("Running");
00424   
00425   __ffThread =new FFThread;
00426   __ffThread->setInput(text);
00427   __ffThread->setConsole(__console);
00428   __ffThread->start();
00429 
00430   statusBar()->showMessage("Running...", 2000);
00431   usleep(500000);
00432 }

void MainWindow::pause (  )  [private, slot]

Definition at line 434 of file MainWindow.cpp.

References fferr().

Referenced by __buildActionTools().

00435 {
00436   fferr(1) << __FILE__ << ':' << __LINE__ << ": Not implemented\n";
00437 }

void MainWindow::resume (  )  [private, slot]

Definition at line 438 of file MainWindow.cpp.

References fferr().

Referenced by __buildActionTools().

00439 {
00440   fferr(1) << __FILE__ << ':' << __LINE__ << ": Not implemented\n";
00441 }

void MainWindow::stop (  )  [private, slot]

Definition at line 443 of file MainWindow.cpp.

References __ffThread.

Referenced by __buildActionTools().

00444 {
00445   if (__ffThread != 0) {
00446     __ffThread->terminate();
00447     delete __ffThread;
00448   }
00449 }

void MainWindow::aboutff3d (  )  [private, slot]

Definition at line 452 of file MainWindow.cpp.

Referenced by __buildHelpTools().

00453 {
00454     QMessageBox::about(this, "FreeFEM3D",
00455                         "FreeFEM3D, blablabla");
00456 }

void MainWindow::aboutQt (  )  [private, slot]

Definition at line 459 of file MainWindow.cpp.

Referenced by __buildHelpTools().

00460 {
00461     QMessageBox::aboutQt(this, "Qt blabla");
00462 }

void MainWindow::aboutVtk (  )  [private, slot]

Definition at line 464 of file MainWindow.cpp.

Referenced by __buildHelpTools().

00465 {
00466     QMessageBox::about(this, "Vtk", "Vtk blabla");
00467 }

void MainWindow::__buildFileTools (  )  [private]

Definition at line 81 of file MainWindow.cpp.

References choose(), newFile(), print(), save(), and saveAs().

Referenced by MainWindow().

00082 {
00083     QAction * fileNewAction;
00084     QAction * fileOpenAction;
00085     QAction * fileSaveAction, * fileSaveAsAction, * filePrintAction;
00086     QAction * fileCloseAction, * fileQuitAction;
00087 
00088     fileNewAction = new QAction("&New", this);
00089     connect(fileNewAction, SIGNAL(activated()), this,
00090              SLOT(newFile()));
00091     fileNewAction->setShortcut(tr("Ctrl+N"));
00092 
00093     fileOpenAction = new QAction(QPixmap(fileopen), "&Open...", this);
00094     connect(fileOpenAction, SIGNAL(activated()), this, SLOT(choose()));
00095 
00096     fileOpenAction->setShortcut(tr("Ctrl+O"));
00097     const char * fileOpenText =
00098       "<p><img source=\"fileopen\"> "
00099       "Click this button to open a <it>new file</it>. <br>"
00100       "You can also select the <b>Open</b> command "
00101       "from the <b>File</b> menu.</p>";
00102 //     QMimeSourceFactory::defaultFactory()->setPixmap("fileopen",
00103 //                           fileOpenAction->iconSet().pixmap());
00104     fileOpenAction->setWhatsThis(fileOpenText);
00105 
00106     fileSaveAction = new QAction(QPixmap(filesave), "&Save", this);
00107     connect(fileSaveAction, SIGNAL(activated()), this, SLOT(save()));
00108 
00109     fileSaveAction->setShortcut(tr("Ctrl+S"));
00110     const char * fileSaveText =
00111       "<p>Click this button to save the file you "
00112       "are editing. You will be prompted for a file name.\n"
00113       "You can also select the <b>Save</b> command "
00114       "from the <b>File</b> menu.</p>";
00115     fileSaveAction->setWhatsThis(fileSaveText);
00116 
00117     fileSaveAsAction = new QAction(tr("Save &As..."),  this);
00118     connect(fileSaveAsAction, SIGNAL(activated()), this,
00119              SLOT(saveAs()));
00120     fileSaveAsAction->setWhatsThis(fileSaveText);
00121 
00122     filePrintAction = new QAction(QPixmap(fileprint), tr("&Print..."), this);
00123     connect(filePrintAction, SIGNAL(activated()), this,
00124              SLOT(print()));
00125     filePrintAction->setShortcut(tr("Ctrl+P"));
00126 
00127     const char * filePrintText = "Click this button to print the file you "
00128                      "are editing.\n You can also select the Print "
00129                      "command from the File menu.";
00130     filePrintAction->setWhatsThis(filePrintText);
00131 
00132     fileCloseAction = new QAction("&Close", this);
00133     connect(fileCloseAction, SIGNAL(activated()), this,
00134              SLOT(close()));
00135     fileCloseAction->setShortcut(tr("Ctrl+W"));
00136 
00137     fileQuitAction = new QAction(tr("&Quit"), this);
00138     connect(fileQuitAction, SIGNAL(activated()), qApp,
00139              SLOT(closeAllWindows()));
00140     fileQuitAction->setShortcut(tr("Ctrl+Q"));
00141 
00142     // populate a tool bar with some actions
00143 
00144     QToolBar * fileTools = addToolBar(tr("File operations"));
00145     fileTools->addAction(fileOpenAction);
00146     fileTools->addAction(fileSaveAction);
00147     fileTools->addAction(filePrintAction);
00148 
00149 //     (void)QWhatsThis::whatsThisButton(fileTools);
00150 
00151 
00152     // populate a menu with all actions
00153 
00154     QMenu * file = new QMenu(tr("&File"), this);
00155     menuBar()->addMenu(file);
00156     file->addAction(fileNewAction);
00157     file->addAction(fileOpenAction);
00158     file->addAction(fileSaveAction);
00159     file->addAction(fileSaveAsAction);
00160     file->addSeparator();
00161     file->addAction(filePrintAction);
00162     file->addSeparator();
00163     file->addAction(fileCloseAction);
00164     file->addAction(fileQuitAction);
00165 }

void MainWindow::__buildEditorTools (  )  [private]

Definition at line 167 of file MainWindow.cpp.

References __editor.

Referenced by MainWindow().

00168 {
00169     QMenu * editorMenu = new QMenu(tr("&Editor"), this);
00170     menuBar()->addMenu(editorMenu);
00171     editorMenu->addAction(tr("&Undo"), __editor, SLOT(undo()), tr("Ctrl+Z"));
00172     editorMenu->addAction(tr("&Redo"), __editor, SLOT(redo()), tr("Ctrl+Y"));
00173     editorMenu->addSeparator();
00174     editorMenu->addAction(tr("Cu&t"),  __editor, SLOT(cut()),  tr("Ctrl+X"));
00175     editorMenu->addAction(tr("&Copy"), __editor, SLOT(copy()), tr("Ctrl+C"));
00176     editorMenu->addAction(tr("&Paste"),__editor, SLOT(paste()),tr("Ctrl+V"));
00177     editorMenu->addSeparator();
00178     editorMenu->addAction(tr("Select All"), __editor, SLOT(selectAll()));
00179     editorMenu->addSeparator();
00180     editorMenu->addAction(tr("Change &Font"),__editor, SLOT(fontDialogue()));
00181     
00182 //     editorMenu->addAction(fileNewAction);
00183 }

void MainWindow::__buildActionTools (  )  [private]

Definition at line 186 of file MainWindow.cpp.

References pause(), resume(), run(), and stop().

Referenced by MainWindow().

00187 {
00188   // adds the action menu
00189   QMenu * action = new QMenu("&Action", this);
00190   menuBar()->addMenu(action);
00191   action->addAction(tr("&Run"), this, SLOT(run()),
00192                       tr("Ctrl+R"));
00193   action->addAction(tr("&Pause"), this, SLOT(pause()));
00194   action->addAction(tr("&Resume"), this, SLOT(resume()));
00195   action->addAction(tr("&Stop"), this, SLOT(stop()));
00196 }

void MainWindow::__buildHelpTools (  )  [private]

Definition at line 198 of file MainWindow.cpp.

References aboutff3d(), aboutQt(), and aboutVtk().

Referenced by MainWindow().

00199 {
00200   QMenu * help = new QMenu(tr("&Help"), this);
00201   menuBar()->addMenu(help);
00202   help->addAction(tr("&About"), this, SLOT(aboutff3d()),
00203                   tr("F1"));
00204   help->addAction(tr("About &Qt"), this, SLOT(aboutQt()));
00205   help->addAction(tr("About &Vtk"), this, SLOT(aboutVtk()));
00206   help->addSeparator();
00207   help->addAction(tr("What's &This"), this, SLOT(whatsThis()),
00208                   tr("Shift+F1"));
00209 }


Member Data Documentation

QPrinter* MainWindow::printer [private]

Definition at line 74 of file MainWindow.hpp.

Referenced by MainWindow(), print(), and ~MainWindow().

Definition at line 75 of file MainWindow.hpp.

Referenced by __buildEditorTools(), closeEvent(), load(), MainWindow(), run(), and save().

QTextEdit* MainWindow::__console [private]

Definition at line 76 of file MainWindow.hpp.

Referenced by MainWindow(), and run().

QString MainWindow::filename [private]

Definition at line 77 of file MainWindow.hpp.

Referenced by choose(), save(), and saveAs().

Definition at line 78 of file MainWindow.hpp.

Referenced by run(), stop(), and ~MainWindow().


The documentation for this class was generated from the following files:

Generated on Wed Nov 19 00:08:45 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6