diff gui/src/FileEditorMdiSubWindow.cpp @ 13506:c70511cf64ee

Reformatted to GNU Style.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Sun, 17 Jul 2011 22:59:28 +0200
parents 13e3d60aff2d
children 8c143d6d0330
line wrap: on
line diff
--- a/gui/src/FileEditorMdiSubWindow.cpp	Sun Jul 17 20:37:14 2011 +0200
+++ b/gui/src/FileEditorMdiSubWindow.cpp	Sun Jul 17 22:59:28 2011 +0200
@@ -26,140 +26,174 @@
 #include <QStyle>
 #include <QTextStream>
 
-FileEditorMdiSubWindow::FileEditorMdiSubWindow(QWidget *parent)
-    : QMdiSubWindow(parent) {
-    construct();
+FileEditorMdiSubWindow::FileEditorMdiSubWindow (QWidget * parent):QMdiSubWindow
+  (parent)
+{
+  construct ();
 }
 
-FileEditorMdiSubWindow::~FileEditorMdiSubWindow() {
-    while(checkFileModified("Close File")) {
-    } // don't close if something went wrong while saving the file
+FileEditorMdiSubWindow::~FileEditorMdiSubWindow ()
+{
+  while (checkFileModified ("Close File"))
+    {
+    }				// don't close if something went wrong while saving the file
 }
 
-void FileEditorMdiSubWindow::loadFile(QString fileName) {    
-    QFile file(fileName);
-    if (!file.open(QFile::ReadOnly)) {
-        QMessageBox::warning(this, tr("File Editor"),
-                             tr("Cannot read file %1:\n%2.")
-                             .arg(fileName)
-                             .arg(file.errorString()));
-        return;
+void
+FileEditorMdiSubWindow::loadFile (QString fileName)
+{
+  QFile file (fileName);
+  if (!file.open (QFile::ReadOnly))
+    {
+      QMessageBox::warning (this, tr ("File Editor"),
+			    tr ("Cannot read file %1:\n%2.").arg (fileName).
+			    arg (file.errorString ()));
+      return;
     }
 
-    QTextStream in(&file);
-    QApplication::setOverrideCursor(Qt::WaitCursor);
-    m_editor->setText(in.readAll());
-    QApplication::restoreOverrideCursor();
+  QTextStream in (&file);
+  QApplication::setOverrideCursor (Qt::WaitCursor);
+  m_editor->setText (in.readAll ());
+  QApplication::restoreOverrideCursor ();
+
+  m_fileName = fileName;
+  setWindowTitle (fileName);
+  m_statusBar->showMessage (tr ("File loaded."), 2000);
+  m_editor->setModified (false);
+}
 
-    m_fileName = fileName;
-    setWindowTitle(fileName);
-    m_statusBar->showMessage(tr("File loaded."), 2000);
-    m_editor->setModified(false);
+void
+FileEditorMdiSubWindow::newFile ()
+{
+  if (checkFileModified ("Open New File"))
+    {
+      return;			// something went wrong while saving the old file
+    }
+  m_fileName = "<unnamed>";
+  setWindowTitle (m_fileName);
+  m_editor->setText ("");
+  m_editor->setModified (false);
 }
 
-void FileEditorMdiSubWindow::newFile() {
-    if(checkFileModified("Open New File")) {
-        return;  // something went wrong while saving the old file
-    }
-    m_fileName = "<unnamed>";
-    setWindowTitle(m_fileName);
-    m_editor->setText("");
-    m_editor->setModified(false);
-}
+int
+FileEditorMdiSubWindow::checkFileModified (QString msg)
+{
+  if (m_editor->isModified ())
+    {
+      int decision = QMessageBox::question (this,
+					    msg,
+					    "Do you want to save the current file?",
+					    QMessageBox::Yes,
+					    QMessageBox::No);
 
-int FileEditorMdiSubWindow::checkFileModified(QString msg) {
-    if(m_editor->isModified()) {
-        int decision
-                = QMessageBox::question(this,
-                                        msg,
-                                        "Do you want to save the current file?",
-                                        QMessageBox::Yes, QMessageBox::No);
-
-        if(decision == QMessageBox::Yes) {
-            saveFile();
-            if(m_editor->isModified()) {
-                // If the user attempted to save the file, but it's still
-                // modified, then probably something went wrong, so return error
-                return(1);
-            }
-        }
+      if (decision == QMessageBox::Yes)
+	{
+	  saveFile ();
+	  if (m_editor->isModified ())
+	    {
+	      // If the user attempted to save the file, but it's still
+	      // modified, then probably something went wrong, so return error
+	      return (1);
+	    }
+	}
     }
-    return(0);
+  return (0);
 }
 
-void FileEditorMdiSubWindow::saveFile() {
-    if(m_fileName.isEmpty()) {
-        m_fileName = QFileDialog::getSaveFileName(this, "Save File", m_fileName);
-        if(m_fileName.isEmpty())
-            return;
+void
+FileEditorMdiSubWindow::saveFile ()
+{
+  if (m_fileName.isEmpty ())
+    {
+      m_fileName =
+	QFileDialog::getSaveFileName (this, "Save File", m_fileName);
+      if (m_fileName.isEmpty ())
+	return;
     }
 
-    QFile file(m_fileName);
-    if (!file.open(QFile::WriteOnly)) {
-        QMessageBox::warning(this, tr("File Editor"),
-                             tr("Cannot write file %1:\n%2.")
-                             .arg(m_fileName)
-                             .arg(file.errorString()));
-        return;
+  QFile file (m_fileName);
+  if (!file.open (QFile::WriteOnly))
+    {
+      QMessageBox::warning (this, tr ("File Editor"),
+			    tr ("Cannot write file %1:\n%2.").
+			    arg (m_fileName).arg (file.errorString ()));
+      return;
     }
 
-    QTextStream out(&file);
-    QApplication::setOverrideCursor(Qt::WaitCursor);
-    out << m_editor->text();
-    QApplication::restoreOverrideCursor();
-    m_statusBar->showMessage(tr("File saved"), 2000);
+  QTextStream out (&file);
+  QApplication::setOverrideCursor (Qt::WaitCursor);
+  out << m_editor->text ();
+  QApplication::restoreOverrideCursor ();
+  m_statusBar->showMessage (tr ("File saved"), 2000);
 }
 
-void FileEditorMdiSubWindow::saveFileAs() {/*
-    QString saveFileName = QFileDialog::getSaveFileName(this, "Save File", m_fileName);
-    if(saveFileName.isEmpty())
-        return;
+void
+FileEditorMdiSubWindow::saveFileAs ()
+{				/*
+				   QString saveFileName = QFileDialog::getSaveFileName(this, "Save File", m_fileName);
+				   if(saveFileName.isEmpty())
+				   return;
 
-    QFile file(saveFileName);
-    file.open(QFile::WriteOnly);
+				   QFile file(saveFileName);
+				   file.open(QFile::WriteOnly);
 
-    if(file.write(m_simpleEditor->toPlainText().toLocal8Bit()) == -1) {
-        QMessageBox::warning(this,
-                             "Error Saving File",
-                             QString("The file could not be saved: %1.").arg(file.errorString()));
-    } else {
-        m_simpleEditor->document()->setModified(false);
-        m_fileName = saveFileName;
-        setWindowTitle(m_fileName);
-    }
+				   if(file.write(m_simpleEditor->toPlainText().toLocal8Bit()) == -1) {
+				   QMessageBox::warning(this,
+				   "Error Saving File",
+				   QString("The file could not be saved: %1.").arg(file.errorString()));
+				   } else {
+				   m_simpleEditor->document()->setModified(false);
+				   m_fileName = saveFileName;
+				   setWindowTitle(m_fileName);
+				   }
 
-    file.close();*/
+				   file.close(); */
 }
 
-void FileEditorMdiSubWindow::showToolTipNew() {
-    m_statusBar->showMessage("Create a new file.", 2000);
+void
+FileEditorMdiSubWindow::showToolTipNew ()
+{
+  m_statusBar->showMessage ("Create a new file.", 2000);
 }
 
-void FileEditorMdiSubWindow::showToolTipSave() {
-    m_statusBar->showMessage("Save the file.", 2000);
+void
+FileEditorMdiSubWindow::showToolTipSave ()
+{
+  m_statusBar->showMessage ("Save the file.", 2000);
 }
 
-void FileEditorMdiSubWindow::showToolTipSaveAs() {
-    m_statusBar->showMessage("Save the file as.", 2000);
+void
+FileEditorMdiSubWindow::showToolTipSaveAs ()
+{
+  m_statusBar->showMessage ("Save the file as.", 2000);
 }
-void FileEditorMdiSubWindow::showToolTipUndo() {
-    m_statusBar->showMessage("Revert previous changes.", 2000);
+
+void
+FileEditorMdiSubWindow::showToolTipUndo ()
+{
+  m_statusBar->showMessage ("Revert previous changes.", 2000);
 }
 
-void FileEditorMdiSubWindow::showToolTipRedo() {
-    m_statusBar->showMessage("Append previous changes.", 2000);
+void
+FileEditorMdiSubWindow::showToolTipRedo ()
+{
+  m_statusBar->showMessage ("Append previous changes.", 2000);
 }
 
-void FileEditorMdiSubWindow::registerModified(bool modified) {
-    m_modified = modified;
+void
+FileEditorMdiSubWindow::registerModified (bool modified)
+{
+  m_modified = modified;
 }
 
-void FileEditorMdiSubWindow::construct() {
-    QStyle *style = QApplication::style();
-    setWidget(new QWidget());
-    m_toolBar = new QToolBar(this);
-    m_statusBar = new QStatusBar(this);
-    m_editor = new QsciScintilla(this);
+void
+FileEditorMdiSubWindow::construct ()
+{
+  QStyle *style = QApplication::style ();
+  setWidget (new QWidget ());
+  m_toolBar = new QToolBar (this);
+  m_statusBar = new QStatusBar (this);
+  m_editor = new QsciScintilla (this);
 
 // Not available in the Debian repos yet!
 /*
@@ -171,55 +205,60 @@
     m_editor->setLexer(m_lexer);
 */
 
-    m_editor->setMarginType(1,QsciScintilla::TextMargin);
-    m_editor->setMarginType(2,QsciScintilla::SymbolMargin);
-    m_editor->setFolding(QsciScintilla::BoxedTreeFoldStyle,2);
-    m_editor->setMarginLineNumbers(1, true);
-    m_editor->setMarginWidth(1, "99999");
+  m_editor->setMarginType (1, QsciScintilla::TextMargin);
+  m_editor->setMarginType (2, QsciScintilla::SymbolMargin);
+  m_editor->setFolding (QsciScintilla::BoxedTreeFoldStyle, 2);
+  m_editor->setMarginLineNumbers (1, true);
+  m_editor->setMarginWidth (1, "99999");
+
+  m_editor->setBraceMatching (QsciScintilla::SloppyBraceMatch);
+  m_editor->setAutoIndent (true);
+  m_editor->setIndentationWidth (2);
+  m_editor->setIndentationsUseTabs (false);
+  m_editor->setAutoCompletionThreshold (2);
 
-    m_editor->setBraceMatching(QsciScintilla::SloppyBraceMatch);
-    m_editor->setAutoIndent(true);
-    m_editor->setIndentationWidth(2);
-    m_editor->setIndentationsUseTabs(false);
-    m_editor->setAutoCompletionThreshold(2);
-
-    QAction *newAction = new QAction(style->standardIcon(QStyle::SP_FileIcon),
-        "", m_toolBar);
-    QAction *saveAction = new QAction(style->standardIcon(QStyle::SP_DriveHDIcon),
-        "", m_toolBar);
-    QAction *saveActionAs = new QAction(style->standardIcon(QStyle::SP_DriveFDIcon),
-        "", m_toolBar);
-    QAction *undoAction = new QAction(style->standardIcon(QStyle::SP_ArrowLeft),
-        "", m_toolBar);
-    QAction *redoAction = new QAction(style->standardIcon(QStyle::SP_ArrowRight),
-        "", m_toolBar);
+  QAction *newAction = new QAction (style->standardIcon (QStyle::SP_FileIcon),
+				    "", m_toolBar);
+  QAction *saveAction =
+    new QAction (style->standardIcon (QStyle::SP_DriveHDIcon),
+		 "", m_toolBar);
+  QAction *saveActionAs =
+    new QAction (style->standardIcon (QStyle::SP_DriveFDIcon),
+		 "", m_toolBar);
+  QAction *undoAction =
+    new QAction (style->standardIcon (QStyle::SP_ArrowLeft),
+		 "", m_toolBar);
+  QAction *redoAction =
+    new QAction (style->standardIcon (QStyle::SP_ArrowRight),
+		 "", m_toolBar);
 
-    m_toolBar->addAction(newAction);
-    m_toolBar->addAction(saveAction);
-    m_toolBar->addAction(saveActionAs);
-    m_toolBar->addAction(undoAction);
-    m_toolBar->addAction(redoAction);
+  m_toolBar->addAction (newAction);
+  m_toolBar->addAction (saveAction);
+  m_toolBar->addAction (saveActionAs);
+  m_toolBar->addAction (undoAction);
+  m_toolBar->addAction (redoAction);
 
-    QVBoxLayout *layout = new QVBoxLayout();
-    layout->addWidget(m_toolBar);
-    layout->addWidget(m_editor);
-    layout->addWidget(m_statusBar);
-    layout->setMargin(2);
-    widget()->setLayout(layout);
+  QVBoxLayout *layout = new QVBoxLayout ();
+  layout->addWidget (m_toolBar);
+  layout->addWidget (m_editor);
+  layout->addWidget (m_statusBar);
+  layout->setMargin (2);
+  widget ()->setLayout (layout);
 
-    connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
-    connect(undoAction, SIGNAL(triggered()), m_editor, SLOT(undo()));
-    connect(redoAction, SIGNAL(triggered()), m_editor, SLOT(redo()));
-    connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
-    connect(saveActionAs, SIGNAL(triggered()), this, SLOT(saveFileAs()));
+  connect (newAction, SIGNAL (triggered ()), this, SLOT (newFile ()));
+  connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ()));
+  connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ()));
+  connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ()));
+  connect (saveActionAs, SIGNAL (triggered ()), this, SLOT (saveFileAs ()));
 
-    connect(newAction, SIGNAL(hovered()), this, SLOT(showToolTipNew()));
-    connect(undoAction, SIGNAL(hovered()), this, SLOT(showToolTipUndo()));
-    connect(redoAction, SIGNAL(hovered()), this, SLOT(showToolTipRedo()));
-    connect(saveAction, SIGNAL(hovered()), this, SLOT(showToolTipSave()));
-    connect(saveActionAs, SIGNAL(hovered()), this, SLOT(showToolTipSaveAs()));
+  connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ()));
+  connect (undoAction, SIGNAL (hovered ()), this, SLOT (showToolTipUndo ()));
+  connect (redoAction, SIGNAL (hovered ()), this, SLOT (showToolTipRedo ()));
+  connect (saveAction, SIGNAL (hovered ()), this, SLOT (showToolTipSave ()));
+  connect (saveActionAs, SIGNAL (hovered ()), this,
+	   SLOT (showToolTipSaveAs ()));
 
-    m_fileName = "";
-    setWindowTitle(m_fileName);
-    show();
+  m_fileName = "";
+  setWindowTitle (m_fileName);
+  show ();
 }