]> granicus.if.org Git - graphviz/commitdiff
Fix code so that a new graph instance gets assigned the preferred default layout...
authorerg <devnull@localhost>
Fri, 22 Apr 2011 19:40:29 +0000 (19:40 +0000)
committererg <devnull@localhost>
Fri, 22 Apr 2011 19:40:29 +0000 (19:40 +0000)
Fix code so that if the output file name changes, the change is saved and appears the next
time the settings window is open.
Allow NONE for format. In this case, no output file is produced.
Re-format

cmd/gvedit/csettings.cpp
cmd/gvedit/csettings.h
cmd/gvedit/imageviewer.cpp
cmd/gvedit/main.cpp
cmd/gvedit/mainwindow.cpp
cmd/gvedit/mainwindow.h
cmd/gvedit/mdichild.cpp

index 0a985f6b496b5b4ca351942edb328627ceef66c1..db70a1c642f5c5d59e33aa839cb83249570c9dd1 100644 (file)
 
 #define WIDGET(t,f)  ((t*)findChild<t *>(#f))
 typedef struct {
-    const chardata;
+    const char *data;
     int len;
     int cur;
 } rdr_t;
 
-bool loadAttrs(const QString fileName,QComboBox* cbNameG,QComboBox* cbNameN,QComboBox* cbNameE)
+bool loadAttrs(const QString fileName, QComboBox * cbNameG,
+              QComboBox * cbNameN, QComboBox * cbNameE)
 {
     QStringList lines;
     QFile file(fileName);
-    if ( file.open(QIODevice::ReadOnly ) ) {
-        QTextStream stream( &file );
-        QString line;
-        while ( !stream.atEnd() ) {
-            line = stream.readLine(); // line of text excluding '\n'
-           if(line.left(1)==":")
-           {
+    if (file.open(QIODevice::ReadOnly)) {
+       QTextStream stream(&file);
+       QString line;
+       while (!stream.atEnd()) {
+           line = stream.readLine();   // line of text excluding '\n'
+           if (line.left(1) == ":") {
                QString attrName;
-               QStringList sl= line.split(":");
-               for (int id=0;id < sl.count(); id ++)
-               {
-                   if(id==1)
-                       attrName=sl[id];
-                   if(id==2)
-                   {
-                       if(sl[id].contains("G"))
+               QStringList sl = line.split(":");
+               for (int id = 0; id < sl.count(); id++) {
+                   if (id == 1)
+                       attrName = sl[id];
+                   if (id == 2) {
+                       if (sl[id].contains("G"))
                            cbNameG->addItem(attrName);
-                       if(sl[id].contains("N"))
+                       if (sl[id].contains("N"))
                            cbNameN->addItem(attrName);
-                       if(sl[id].contains("E"))
+                       if (sl[id].contains("E"))
                            cbNameE->addItem(attrName);
                    }
                };
            }
-        }
-        file.close();
-    }
-    else {
-        errout << "Could not open attribute name file \"" << fileName << "\" for reading\n" << flush;
+       }
+       file.close();
+    } else {
+       errout << "Could not open attribute name file \"" << fileName <<
+           "\" for reading\n" << flush;
     }
 
     return false;
@@ -71,25 +69,24 @@ bool loadAttrs(const QString fileName,QComboBox* cbNameG,QComboBox* cbNameN,QCom
 QString stripFileExtension(QString fileName)
 {
     int idx;
-    for (idx=fileName.length();idx >=0 ; idx --)
-    {
-       if(fileName.mid(idx,1)==".")
+    for (idx = fileName.length(); idx >= 0; idx--) {
+       if (fileName.mid(idx, 1) == ".")
            break;
     }
     return fileName.left(idx);
 }
 
 
-char* graph_reader( char * str, int num, FILE * stream ) //helper function to load / parse graphs from tstring
+char *graph_reader(char *str, int num, FILE * stream)  //helper function to load / parse graphs from tstring
 {
-    if (num==0)
+    if (num == 0)
        return str;
-    const charptr;
-    charoptr;
+    const char *ptr;
+    char *optr;
     char c;
     int l;
-    rdr_t* s = (rdr_t*)stream;
-    if(s->cur >= s->len)
+    rdr_t *s = (rdr_t *) stream;
+    if (s->cur >= s->len)
        return NULL;
     l = 0;
     ptr = s->data + s->cur;
@@ -97,7 +94,7 @@ char* graph_reader( char * str, int num, FILE * stream ) //helper function to lo
     do {
        *optr++ = c = *ptr++;
        l++;
-    } while (c && (c != '\n') && (l < num-1));
+    } while (c && (c != '\n') && (l < num - 1));
     *optr = '\0';
     s->cur += l;
     return str;
@@ -113,154 +110,184 @@ CFrmSettings::CFrmSettings()
     activeWindow = NULL;
     QString path;
 #ifndef WIN32
-    chars = getenv("GVEDIT_PATH");
+    char *s = getenv("GVEDIT_PATH");
     if (s)
        path = s;
-    else 
+    else
        path = GVEDIT_DATADIR;
 #endif
 
-    connect(WIDGET(QPushButton,pbAdd),SIGNAL(clicked()),this,SLOT(addSlot()));
-    connect(WIDGET(QPushButton,pbNew),SIGNAL(clicked()),this,SLOT(newSlot()));
-    connect(WIDGET(QPushButton,pbOpen),SIGNAL(clicked()),this,SLOT(openSlot()));
-    connect(WIDGET(QPushButton,pbSave),SIGNAL(clicked()),this,SLOT(saveSlot()));
-    connect(WIDGET(QPushButton,btnOK),SIGNAL(clicked()),this,SLOT(okSlot()));
-    connect(WIDGET(QPushButton,btnCancel),SIGNAL(clicked()),this,SLOT(cancelSlot()));
-    connect(WIDGET(QPushButton,pbOut),SIGNAL(clicked()),this,SLOT(outputSlot()));
-    connect(WIDGET(QPushButton,pbHelp),SIGNAL(clicked()),this,SLOT(helpSlot()));
-
-    connect(WIDGET(QComboBox,cbScope),SIGNAL(currentIndexChanged(int)),this,SLOT(scopeChangedSlot(int)));
+    connect(WIDGET(QPushButton, pbAdd), SIGNAL(clicked()), this,
+           SLOT(addSlot()));
+    connect(WIDGET(QPushButton, pbNew), SIGNAL(clicked()), this,
+           SLOT(newSlot()));
+    connect(WIDGET(QPushButton, pbOpen), SIGNAL(clicked()), this,
+           SLOT(openSlot()));
+    connect(WIDGET(QPushButton, pbSave), SIGNAL(clicked()), this,
+           SLOT(saveSlot()));
+    connect(WIDGET(QPushButton, btnOK), SIGNAL(clicked()), this,
+           SLOT(okSlot()));
+    connect(WIDGET(QPushButton, btnCancel), SIGNAL(clicked()), this,
+           SLOT(cancelSlot()));
+    connect(WIDGET(QPushButton, pbOut), SIGNAL(clicked()), this,
+           SLOT(outputSlot()));
+    connect(WIDGET(QPushButton, pbHelp), SIGNAL(clicked()), this,
+           SLOT(helpSlot()));
+
+    connect(WIDGET(QComboBox, cbScope), SIGNAL(currentIndexChanged(int)),
+           this, SLOT(scopeChangedSlot(int)));
     scopeChangedSlot(0);
 
 
 #ifndef WIN32
-    loadAttrs(path + "/attrs.txt",WIDGET(QComboBox,cbNameG),WIDGET(QComboBox,cbNameN),WIDGET(QComboBox,cbNameE));
+    loadAttrs(path + "/attrs.txt", WIDGET(QComboBox, cbNameG),
+             WIDGET(QComboBox, cbNameN), WIDGET(QComboBox, cbNameE));
 #else
-    loadAttrs("../share/graphviz/gvedit/attributes.txt",WIDGET(QComboBox,cbNameG),WIDGET(QComboBox,cbNameN),WIDGET(QComboBox,cbNameE));
+    loadAttrs("../share/graphviz/gvedit/attributes.txt",
+             WIDGET(QComboBox, cbNameG), WIDGET(QComboBox, cbNameN),
+             WIDGET(QComboBox, cbNameE));
 #endif
     setWindowIcon(QIcon(":/images/icon.png"));
 }
 
 void CFrmSettings::outputSlot()
 {
-    QString _filter = "Output File(*."+WIDGET(QComboBox,cbExtension)->currentText()+")";
-    QString fileName = QFileDialog::getSaveFileName(this, tr("Save Graph As.."),"/",_filter);
- if (!fileName.isEmpty())
-     WIDGET(QLineEdit,leOutput)->setText(fileName);
+    QString _filter =
+       "Output File(*." + WIDGET(QComboBox,
+                                 cbExtension)->currentText() + ")";
+    QString fileName =
+       QFileDialog::getSaveFileName(this, tr("Save Graph As.."), "/",
+                                    _filter);
+    if (!fileName.isEmpty())
+       WIDGET(QLineEdit, leOutput)->setText(fileName);
 }
+
 void CFrmSettings::scopeChangedSlot(int id)
 {
-    WIDGET(QComboBox,cbNameG)->setVisible(id==0);
-    WIDGET(QComboBox,cbNameN)->setVisible(id==1);
-    WIDGET(QComboBox,cbNameE)->setVisible(id==2);
+    WIDGET(QComboBox, cbNameG)->setVisible(id == 0);
+    WIDGET(QComboBox, cbNameN)->setVisible(id == 1);
+    WIDGET(QComboBox, cbNameE)->setVisible(id == 2);
 }
+
 void CFrmSettings::addSlot()
 {
-    QString _scope=WIDGET (QComboBox,cbScope)->currentText();
+    QString _scope = WIDGET(QComboBox, cbScope)->currentText();
     QString _name;
-    switch (WIDGET  (QComboBox,cbScope)->currentIndex())
-    {
+    switch (WIDGET(QComboBox, cbScope)->currentIndex()) {
     case 0:
-       _name=WIDGET  (QComboBox,cbNameG)->currentText();
+       _name = WIDGET(QComboBox, cbNameG)->currentText();
        break;
     case 1:
-       _name=WIDGET  (QComboBox,cbNameN)->currentText();
+       _name = WIDGET(QComboBox, cbNameN)->currentText();
        break;
     case 2:
-       _name=WIDGET  (QComboBox,cbNameE)->currentText();
+       _name = WIDGET(QComboBox, cbNameE)->currentText();
        break;
     }
-    QString _value=WIDGET(QLineEdit,leValue)->text();
+    QString _value = WIDGET(QLineEdit, leValue)->text();
 
     if (_value.trimmed().length() == 0)
-       QMessageBox::warning(this, tr("GvEdit"),tr("Please enter a value for selected attribute!"),QMessageBox::Ok,QMessageBox::Ok);
-    else
-    {
-       QString str=_scope+"["+_name+"=\"";
-       if(WIDGET (QTextEdit,teAttributes)->toPlainText().contains(str))
-       {
-           QMessageBox::warning(this, tr("GvEdit"),tr("Attribute is already defined!"),QMessageBox::Ok,QMessageBox::Ok);
+       QMessageBox::warning(this, tr("GvEdit"),
+                            tr
+                            ("Please enter a value for selected attribute!"),
+                            QMessageBox::Ok, QMessageBox::Ok);
+    else {
+       QString str = _scope + "[" + _name + "=\"";
+       if (WIDGET(QTextEdit, teAttributes)->toPlainText().contains(str)) {
+           QMessageBox::warning(this, tr("GvEdit"),
+                                tr("Attribute is already defined!"),
+                                QMessageBox::Ok, QMessageBox::Ok);
            return;
-       }
-       else
-       {
-           str = str + _value+"\"]";
-           WIDGET (QTextEdit,teAttributes)->setPlainText(WIDGET (QTextEdit,teAttributes)->toPlainText()+str+"\n");
+       } else {
+           str = str + _value + "\"]";
+           WIDGET(QTextEdit,
+                  teAttributes)->setPlainText(WIDGET(QTextEdit,
+                                                     teAttributes)->
+                                              toPlainText() + str + "\n");
 
        }
     }
 }
+
 void CFrmSettings::helpSlot()
 {
-    QDesktopServices::openUrl (QUrl("http://www.graphviz.org/doc/info/attrs.html")) ;
+    QDesktopServices::
+       openUrl(QUrl("http://www.graphviz.org/doc/info/attrs.html"));
 }
+
 void CFrmSettings::cancelSlot()
 {
     this->reject();
 }
+
 void CFrmSettings::okSlot()
 {
     saveContent();
     this->done(drawGraph());
 }
+
 void CFrmSettings::newSlot()
 {
-    WIDGET (QTextEdit,teAttributes)->setPlainText(tr(""));
+    WIDGET(QTextEdit, teAttributes)->setPlainText(tr(""));
 }
+
 void CFrmSettings::openSlot()
 {
- QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),"/",tr("Text file (*.*)"));
- if (!fileName.isEmpty())
- {
-    QFile file(fileName);
-    if (!file.open(QFile::ReadOnly | QFile::Text)) {
-        QMessageBox::warning(this, tr("MDI"),
-                             tr("Cannot read file %1:\n%2.")
-                             .arg(fileName)
-                             .arg(file.errorString()));
-        return;
-    }
+    QString fileName =
+       QFileDialog::getOpenFileName(this, tr("Open File"), "/",
+                                    tr("Text file (*.*)"));
+    if (!fileName.isEmpty()) {
+       QFile file(fileName);
+       if (!file.open(QFile::ReadOnly | QFile::Text)) {
+           QMessageBox::warning(this, tr("MDI"),
+                                tr("Cannot read file %1:\n%2.")
+                                .arg(fileName)
+                                .arg(file.errorString()));
+           return;
+       }
 
-    QTextStream in(&file);
-    WIDGET (QTextEdit,teAttributes)->setPlainText(in.readAll());
- }
+       QTextStream in(&file);
+       WIDGET(QTextEdit, teAttributes)->setPlainText(in.readAll());
   }
 
 }
-void CFrmSettings::saveSlot(){
 
-    if(WIDGET (QTextEdit,teAttributes)->toPlainText().trimmed().length()==0)
-    {
-       QMessageBox::warning(this, tr("GvEdit"),tr("Nothing to save!"),QMessageBox::Ok,QMessageBox::Ok);
+void CFrmSettings::saveSlot()
+{
+
+    if (WIDGET(QTextEdit, teAttributes)->toPlainText().trimmed().
+       length() == 0) {
+       QMessageBox::warning(this, tr("GvEdit"), tr("Nothing to save!"),
+                            QMessageBox::Ok, QMessageBox::Ok);
        return;
 
 
     }
 
     QString fileName = QFileDialog::getSaveFileName(this, tr("Open File"),
-                                                "/",
-                                                 tr("Text File(*.*)"));
- if (!fileName.isEmpty())
- {
+                                                   "/",
+                                                   tr("Text File(*.*)"));
+    if (!fileName.isEmpty()) {
+
+       QFile file(fileName);
+       if (!file.open(QFile::WriteOnly | QFile::Text)) {
+           QMessageBox::warning(this, tr("MDI"),
+                                tr("Cannot write file %1:\n%2.")
+                                .arg(fileName)
+                                .arg(file.errorString()));
+           return;
+       }
 
-    QFile file(fileName);
-    if (!file.open(QFile::WriteOnly | QFile::Text)) {
-        QMessageBox::warning(this, tr("MDI"),
-                             tr("Cannot write file %1:\n%2.")
-                             .arg(fileName)
-                             .arg(file.errorString()));
-        return;
+       QTextStream out(&file);
+       out << WIDGET(QTextEdit, teAttributes)->toPlainText();
+       return;
     }
 
-    QTextStream out(&file);
-    out << WIDGET (QTextEdit,teAttributes)->toPlainText();
-    return;
- }
-
 }
 
-bool CFrmSettings::loadGraph(MdiChild* m)
+bool CFrmSettings::loadGraph(MdiChild * m)
 {
-    if(graph)
+    if (graph)
        agclose(graph);
     graphData.clear();
     graphData.append(m->toPlainText());
@@ -268,78 +295,94 @@ bool CFrmSettings::loadGraph(MdiChild* m)
     return true;
 
 }
+
 bool CFrmSettings::createLayout()
 {
     rdr_t rdr;
     //first attach attributes to graph
-    int _pos=graphData.indexOf(tr("{"));
-    graphData.replace(_pos,1,"{"+WIDGET(QTextEdit,teAttributes)->toPlainText());
-
-      /* Reset line number and file name;
-       * If known, might want to use real name
-       */
+    int _pos = graphData.indexOf(tr("{"));
+    graphData.replace(_pos, 1,
+                     "{" + WIDGET(QTextEdit,
+                                  teAttributes)->toPlainText());
+
+    /* Reset line number and file name;
+     * If known, might want to use real name
+     */
     agsetfile("<gvedit>");
     QByteArray bytes = graphData.toUtf8();
     rdr.data = bytes.constData();
     rdr.len = strlen(rdr.data);
     rdr.cur = 0;
-    graph = agread_usergets((FILE*)&rdr,(gets_f)graph_reader);
+    graph = agread_usergets((FILE *) & rdr, (gets_f) graph_reader);
     /* graph=agread_usergets(reinterpret_cast<FILE*>(this),(gets_f)graph_reader); */
-    if(!graph)
+    if (!graph)
        return false;
     if (agerrors()) {
-       agclose (graph);
+       agclose(graph);
        graph = NULL;
        return false;
     }
-    Agraph_t* G=this->graph;
-    gvLayout (gvc, G, (char*)WIDGET(QComboBox,cbLayout)->currentText().toUtf8().constData()); /* library function */
+    Agraph_t *G = this->graph;
+    gvLayout(gvc, G, (char *) WIDGET(QComboBox, cbLayout)->currentText().toUtf8().constData());        /* library function */
     return true;
 }
-QString buildTempFile()
+
+static QString buildTempFile()
 {
     QTemporaryFile tempFile;
     tempFile.setAutoRemove(false);
     tempFile.open();
-    QString a=tempFile.fileName();
+    QString a = tempFile.fileName();
     tempFile.close();
     return a;
 }
 
-bool CFrmSettings::renderLayout()
+void CFrmSettings::doPreview(QString fileName)
 {
-    if(graph)
-    {
-       QString _fileName(WIDGET(QLineEdit,leOutput)->text());
-       _fileName=stripFileExtension(_fileName);
-       _fileName=_fileName+"."+WIDGET(QComboBox,cbExtension)->currentText();
-       int rv=gvRenderFilename(gvc,graph,(char*)WIDGET(QComboBox,cbExtension)->currentText().toUtf8().constData(),(char*)_fileName.toUtf8().constData());
-       if(rv)
-           return false;
-
-       if(getActiveWindow()->previewFrm)
-       {
-           getActiveWindow()->parentFrm->mdiArea->removeSubWindow(getActiveWindow()->previewFrm->subWindowRef);
-           delete getActiveWindow()->previewFrm;
-           getActiveWindow()->previewFrm=NULL;
-
-       }
-       if(!this->getActiveWindow()->loadPreview(_fileName));//create preview
-       {
-           QString prevFile(buildTempFile());
-           gvRenderFilename(gvc,graph,"png",(char*)prevFile.toUtf8().constData());
-           this->getActiveWindow()->loadPreview(prevFile);
+    if (getActiveWindow()->previewFrm) {
+       getActiveWindow()->parentFrm->mdiArea->
+           removeSubWindow(getActiveWindow()->previewFrm->subWindowRef);
+       delete getActiveWindow()->previewFrm;
+       getActiveWindow()->previewFrm = NULL;
+    }
 
-/*         if(!this->getActiveWindow()->loadPreview(prevFile))
-               QMessageBox::information(this, tr("GVEdit"),
-                                       tr("Preview file can not be opened."));*/
+    if ((fileName.isNull()) || !(getActiveWindow()->loadPreview(fileName))) {  //create preview
+       QString prevFile(buildTempFile());
+       gvRenderFilename(gvc, graph, "png",
+                        (char *) prevFile.toUtf8().constData());
+       getActiveWindow()->loadPreview(prevFile);
+#if 0
+       if (!this->getActiveWindow()->loadPreview(prevFile))
+           QMessageBox::information(this, tr("GVEdit"),
+                                    tr
+                                    ("Preview file can not be opened."));
+#endif
+    }
+}
 
-       }
+bool CFrmSettings::renderLayout()
+{
+    if (!graph)
+       return false;
+    QString sfx = WIDGET(QComboBox, cbExtension)->currentText();
 
-       return true;
+    if (sfx == QString("NONE"))
+       doPreview(QString());
+    else {
+       QString fileName(WIDGET(QLineEdit, leOutput)->text());
+       fileName = stripFileExtension(fileName);
+       fileName = fileName + "." + sfx;
+       if (fileName != activeWindow->outputFile)
+           activeWindow->outputFile = fileName;
+
+       if (gvRenderFilename
+           (gvc, graph, (char *) sfx.toUtf8().constData(),
+            (char *) fileName.toUtf8().constData()))
+           return false;
 
+       doPreview(fileName);
     }
-    return false;
+    return true;
 }
 
 
@@ -357,76 +400,79 @@ bool CFrmSettings::loadRenderers()
 void CFrmSettings::refreshContent()
 {
 
-    WIDGET(QComboBox,cbLayout)->setCurrentIndex(activeWindow->layoutIdx);
-    WIDGET(QComboBox,cbExtension)->setCurrentIndex(activeWindow->renderIdx);
-    if(!activeWindow->outputFile.isEmpty())
-       WIDGET(QLineEdit,leOutput)->setText(activeWindow->outputFile);
+    WIDGET(QComboBox, cbLayout)->setCurrentIndex(activeWindow->layoutIdx);
+    WIDGET(QComboBox,
+          cbExtension)->setCurrentIndex(activeWindow->renderIdx);
+    if (!activeWindow->outputFile.isEmpty())
+       WIDGET(QLineEdit, leOutput)->setText(activeWindow->outputFile);
     else
-       WIDGET(QLineEdit,leOutput)->setText(stripFileExtension(activeWindow->currentFile())+  "."+WIDGET(QComboBox,cbExtension)->currentText());
+       WIDGET(QLineEdit,
+              leOutput)->setText(stripFileExtension(activeWindow->
+                                                    currentFile()) + "." +
+                                 WIDGET(QComboBox,
+                                        cbExtension)->currentText());
 
-    WIDGET(QTextEdit,teAttributes)->setText(activeWindow->attributes);
+    WIDGET(QTextEdit, teAttributes)->setText(activeWindow->attributes);
 
-    WIDGET(QLineEdit,leValue)->setText("");
+    WIDGET(QLineEdit, leValue)->setText("");
 
 }
 
 void CFrmSettings::saveContent()
 {
-    activeWindow->layoutIdx=WIDGET(QComboBox,cbLayout)->currentIndex();
-    activeWindow->renderIdx=WIDGET(QComboBox,cbExtension)->currentIndex();
-    activeWindow->outputFile=WIDGET(QLineEdit,leOutput)->text();
-    activeWindow->attributes=WIDGET(QTextEdit,teAttributes)->toPlainText();
+    activeWindow->layoutIdx = WIDGET(QComboBox, cbLayout)->currentIndex();
+    activeWindow->renderIdx =
+       WIDGET(QComboBox, cbExtension)->currentIndex();
+    activeWindow->outputFile = WIDGET(QLineEdit, leOutput)->text();
+    activeWindow->attributes =
+       WIDGET(QTextEdit, teAttributes)->toPlainText();
 }
+
 int CFrmSettings::drawGraph()
 {
     int rc;
     if (createLayout() && renderLayout()) {
-       getActiveWindow()->settingsSet=false;
+       getActiveWindow()->settingsSet = false;
        rc = QDialog::Accepted;
-    }
-    else
+    } else
        rc = QDialog::Accepted;
-    agreseterrors ();
+    agreseterrors();
 
     return rc;
-       /* return QDialog::Rejected; */
+    /* return QDialog::Rejected; */
 }
 
-int CFrmSettings::runSettings(MdiChild* m)
+int CFrmSettings::runSettings(MdiChild * m)
 {
-    if ((m) && (m==getActiveWindow()))
-    {
-        if(this->loadGraph(m))
+    if ((m) && (m == getActiveWindow())) {
+       if (this->loadGraph(m))
            return drawGraph();
        else
-            return QDialog::Rejected;
+           return QDialog::Rejected;
     }
 
     else
        return showSettings(m);
 
 }
-int CFrmSettings::showSettings(MdiChild* m)
+
+int CFrmSettings::showSettings(MdiChild * m)
 {
 
-        if(this->loadGraph(m))
-       {
-           refreshContent();
-           return this->exec();
-       }
-       else
-           return QDialog::Rejected;
+    if (this->loadGraph(m)) {
+       refreshContent();
+       return this->exec();
+    } else
+       return QDialog::Rejected;
 }
 
-void CFrmSettings::setActiveWindow(MdiChild* m)
+void CFrmSettings::setActiveWindow(MdiChild * m)
 {
-    this->activeWindow=m;
+    this->activeWindow = m;
 
 }
-MdiChild* CFrmSettings::getActiveWindow()
+
+MdiChild *CFrmSettings::getActiveWindow()
 {
     return activeWindow;
 }
-
-
-
index c000592dacd3eecf4de61a5e4b417db42e6fc0af..79d0949b71aed54f88337696c213e81a1666f296 100644 (file)
@@ -64,6 +64,7 @@ private:
     bool loadRenderers();
     void refreshContent();
     void saveContent();
+    void doPreview(QString);
     void setActiveWindow(MdiChild* m);
     bool loadGraph(MdiChild* m);
     bool createLayout();
index edfce60053f86a5ed25e21696606a43b9404ac4e..a268c889fb364213d2f458960bd6fe37d94f9943 100644 (file)
@@ -15,7 +15,7 @@
 #include "imageviewer.h"
 #include "mdichild.h"
 
-extern int errorPipe(charerrMsg);
+extern int errorPipe(char *errMsg);
 
 
 //! [0]
@@ -40,6 +40,7 @@ ImageViewer::ImageViewer()
     setWindowIcon(QIcon(":/images/icon.png"));
 
 }
+
 //! [0]
 
 //! [1]
@@ -47,20 +48,21 @@ bool ImageViewer::open(QString fileName)
 //! [1] //! [2]
 {
     if (!fileName.isEmpty()) {
-        QImage image(fileName);
-        if (image.isNull()) {
-            return false;
-        }
-        imageLabel->setPixmap(QPixmap::fromImage(image));
-        scaleFactor = 1.0;
-        fitToWindowAct->setEnabled(true);
-        updateActions();
-
-        if (!fitToWindowAct->isChecked())
-            imageLabel->adjustSize();
+       QImage image(fileName);
+       if (image.isNull()) {
+           return false;
+       }
+       imageLabel->setPixmap(QPixmap::fromImage(image));
+       scaleFactor = 1.0;
+       fitToWindowAct->setEnabled(true);
+       updateActions();
+
+       if (!fitToWindowAct->isChecked())
+           imageLabel->adjustSize();
     }
     return true;
 }
+
 void ImageViewer::print()
 {
     Q_ASSERT(imageLabel->pixmap());
@@ -69,16 +71,18 @@ void ImageViewer::print()
     QPrintDialog dialog(&printer, this);
 //! [7] //! [8]
     if (dialog.exec()) {
-        QPainter painter(&printer);
-        QRect rect = painter.viewport();
-        QSize size = imageLabel->pixmap()->size();
-        size.scale(rect.size(), Qt::KeepAspectRatio);
-        painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
-        painter.setWindow(imageLabel->pixmap()->rect());
-        painter.drawPixmap(0, 0, *imageLabel->pixmap());
+       QPainter painter(&printer);
+       QRect rect = painter.viewport();
+       QSize size = imageLabel->pixmap()->size();
+       size.scale(rect.size(), Qt::KeepAspectRatio);
+       painter.setViewport(rect.x(), rect.y(), size.width(),
+                           size.height());
+       painter.setWindow(imageLabel->pixmap()->rect());
+       painter.drawPixmap(0, 0, *imageLabel->pixmap());
     }
 #endif
 }
+
 void ImageViewer::zoomIn()
 {
     scaleImage(1.25);
@@ -94,31 +98,35 @@ void ImageViewer::normalSize()
     imageLabel->adjustSize();
     scaleFactor = 1.0;
 }
+
 void ImageViewer::fitToWindow()
 {
     bool fitToWindow = fitToWindowAct->isChecked();
     scrollArea->setWidgetResizable(fitToWindow);
     if (!fitToWindow) {
-        normalSize();
+       normalSize();
     }
     updateActions();
 }
+
 void ImageViewer::about()
 {
     QMessageBox::about(this, tr("About Image Viewer"),
-            tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel "
-               "and QScrollArea to display an image. QLabel is typically used "
-               "for displaying a text, but it can also display an image. "
-               "QScrollArea provides a scrolling view around another widget. "
-               "If the child widget exceeds the size of the frame, QScrollArea "
-               "automatically provides scroll bars. </p><p>The example "
-               "demonstrates how QLabel's ability to scale its contents "
-               "(QLabel::scaledContents), and QScrollArea's ability to "
-               "automatically resize its contents "
-               "(QScrollArea::widgetResizable), can be used to implement "
-               "zooming and scaling features. </p><p>In addition the example "
-               "shows how to use QPainter to print an image.</p>"));
+                      tr
+                      ("<p>The <b>Image Viewer</b> example shows how to combine QLabel "
+                       "and QScrollArea to display an image. QLabel is typically used "
+                       "for displaying a text, but it can also display an image. "
+                       "QScrollArea provides a scrolling view around another widget. "
+                       "If the child widget exceeds the size of the frame, QScrollArea "
+                       "automatically provides scroll bars. </p><p>The example "
+                       "demonstrates how QLabel's ability to scale its contents "
+                       "(QLabel::scaledContents), and QScrollArea's ability to "
+                       "automatically resize its contents "
+                       "(QScrollArea::widgetResizable), can be used to implement "
+                       "zooming and scaling features. </p><p>In addition the example "
+                       "shows how to use QPainter to print an image.</p>"));
 }
+
 void ImageViewer::createActions()
 {
     printAct = new QAction(tr("&Print..."), this);
@@ -149,7 +157,8 @@ void ImageViewer::createActions()
     fitToWindowAct->setEnabled(false);
     fitToWindowAct->setCheckable(true);
     fitToWindowAct->setShortcut(tr("Ctrl+F"));
-    connect(fitToWindowAct, SIGNAL(triggered()), this, SLOT(fitToWindow()));
+    connect(fitToWindowAct, SIGNAL(triggered()), this,
+           SLOT(fitToWindow()));
 
     aboutAct = new QAction(tr("&About"), this);
     connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
@@ -157,9 +166,10 @@ void ImageViewer::createActions()
     aboutQtAct = new QAction(tr("About &Qt"), this);
     connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
 }
+
 void ImageViewer::createMenus()
 {
-    
+
 /*    fileMenu = new QMenu(tr("&File"), this);
     fileMenu->addAction(printAct);
     fileMenu->addSeparator();
@@ -179,14 +189,16 @@ void ImageViewer::createMenus()
 //    menuBar()->addMenu(fileMenu);
     menuBar()->addMenu(viewMenu);
     //menuBar()->addMenu(helpMenu);
-    
+
 }
+
 void ImageViewer::updateActions()
 {
     zoomInAct->setEnabled(!fitToWindowAct->isChecked());
     zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
     normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
 }
+
 void ImageViewer::scaleImage(double factor)
 {
     Q_ASSERT(imageLabel->pixmap());
@@ -199,14 +211,17 @@ void ImageViewer::scaleImage(double factor)
     zoomInAct->setEnabled(scaleFactor < 3.0);
     zoomOutAct->setEnabled(scaleFactor > 0.333);
 }
-void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor)
+
+void ImageViewer::adjustScrollBar(QScrollBar * scrollBar, double factor)
 {
-    scrollBar->setValue(int(factor * scrollBar->value()
-                            + ((factor - 1) * scrollBar->pageStep()/2)));
+    scrollBar->setValue(int (factor * scrollBar->value()
+                            +
+                            ((factor - 1) * scrollBar->pageStep() / 2)));
 }
-void ImageViewer::closeEvent(QCloseEvent *event)
+
+void ImageViewer::closeEvent(QCloseEvent * event)
 {
-    this->graphWindow->previewFrm=NULL;
+    this->graphWindow->previewFrm = NULL;
     event->accept();
 
 }
index 9678442a597924abc15be67fcafe25bfcbc29e55..c9e9c6608f2dc8a53c57c96b644e43e5ed1a96df 100644 (file)
 
 
 #ifdef WIN32_DLL
-__declspec(dllimport) boolean MemTest;
+__declspec(dllimport)
+boolean MemTest;
 /*gvc.lib cgraph.lib*/
 #ifdef WITH_CGRAPH
-    #pragma comment( lib, "cgraph.lib" )
+#pragma comment( lib, "cgraph.lib" )
 #else
-    #pragma comment( lib, "graph.lib" )
-    #pragma comment( lib, "ingraphs.lib" )
-    #pragma comment( lib, "gvc.lib" )
-    #pragma comment( lib, "glib-2.0.lib" )
-    #pragma comment( lib, "pango-1.0.lib" )
-    #pragma comment( lib, "pangocairo-1.0.lib" )
-    #pragma comment( lib, "cairo.lib" )
-    #pragma comment( lib, "gobject-2.0.lib" )
+#pragma comment( lib, "graph.lib" )
+#pragma comment( lib, "ingraphs.lib" )
+#pragma comment( lib, "gvc.lib" )
+#pragma comment( lib, "glib-2.0.lib" )
+#pragma comment( lib, "pango-1.0.lib" )
+#pragma comment( lib, "pangocairo-1.0.lib" )
+#pragma comment( lib, "cairo.lib" )
+#pragma comment( lib, "gobject-2.0.lib" )
 
 #endif
-    #pragma comment( lib, "gvc.lib" )
+#pragma comment( lib, "gvc.lib" )
 #endif
 
-static charcmd;
+static char *cmd;
 
 extern int Verbose;
 
-QTextStream errout (stderr, QIODevice::WriteOnly);
+QTextStream errout(stderr, QIODevice::WriteOnly);
 
-static char *useString =
-    "Usage: gvedit [-v?] <files>\n\
+static char *useString = "Usage: gvedit [-v?] <files>\n\
   -v - verbose\n\
   -? - print usage\n";
 
@@ -81,7 +81,8 @@ static char **parseArgs(int argc, char *argv[])
            if (optopt == '?')
                usage(0);
            else
-               errout << cmd << " : option -" << ((char)optopt) << " unrecognized - ignored\n" << flush;
+               errout << cmd << " : option -" << ((char) optopt) <<
+                   " unrecognized - ignored\n" << flush;
            break;
        }
     }
@@ -101,11 +102,11 @@ int main(int argc, char *argv[])
     int ret;
 
     QApplication app(argc, argv);
-    char** files = parseArgs (argc, argv);
+    char **files = parseArgs(argc, argv);
     CMainWindow mainWin;
     if (files)
        while (*files) {
-           mainWin.addFile (QString(*files));
+           mainWin.addFile(QString(*files));
            files++;
        }
     mainWin.show();
index 02b39b9bb0affd8c9a04f7eb77fdd56b5bdd45ce..b419d980431c1831ad61c53f6a010e52f09f89ea 100644 (file)
 
 #include       <string.h>
 
-QTextEditglobTextEdit;
+QTextEdit *globTextEdit;
 
-int errorPipe(charerrMsg)
+int errorPipe(char *errMsg)
 {
-    globTextEdit->setText(globTextEdit->toPlainText()+QString(errMsg));
+    globTextEdit->setText(globTextEdit->toPlainText() + QString(errMsg));
     return 0;
 }
 
-static void freeList (char** lp, int count)
+static void freeList(char **lp, int count)
 {
     for (int i = 0; i < count; i++)
-       free (lp[i]);
-    free (lp);
+       free(lp[i]);
+    free(lp);
 }
 
-static void LoadPlugins (QComboBox* cb, GVC_t* gvc, char* kind, char* prefer)
+static int LoadPlugins(QComboBox * cb, GVC_t * gvc, char *kind,
+                      char *more[], char *prefer)
 {
     int count;
-    char** lp = gvPluginList(gvc, kind, &count, NULL);
-
-    /* If available, set prefer as first choice */
-    for (int id=0;id < count; id++) {
-       if (!strcmp(prefer,lp[id])) {
-           if (id != 0) {
-               char* tmp = lp[0];
-               lp[0] = lp[id];
-               lp[id] = tmp;
-           }
-           break;
-       }
-    }
+    char **lp = gvPluginList(gvc, kind, &count, NULL);
+    int idx = -1;
 
     cb->clear();
-    for (int id=0;id < count; id++)
-    {
+    for (int id = 0; id < count; id++) {
        cb->addItem(QString(lp[id]));
+       if (prefer && (idx < 0) && !strcmp(prefer, lp[id]))
+           idx = id;
     };
-    freeList (lp, count);
+    freeList(lp, count);
+
+    /* Add additional items if supplied */
+    if (more) {
+       int i = 0;
+       char *s;
+       while ((s = more[i++])) {
+           cb->addItem(QString(s));
+       }
+    }
+
+    if (idx > 0)
+       cb->setCurrentIndex(idx);
+    else
+       idx = 0;
+
+    return idx;
 }
 
 void CMainWindow::createConsole()
 {
     QDockWidget *dock = new QDockWidget(tr("Output Console"), NULL);
-    QTextEdittextEdit = new QTextEdit(dock);
+    QTextEdit *textEdit = new QTextEdit(dock);
 
-    dock->setAllowedAreas(Qt::BottomDockWidgetArea| Qt::TopDockWidgetArea);
+    dock->
+       setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
 //    dock->setWidget(textEdit);
     addDockWidget(Qt::BottomDockWidgetArea, dock);
-    QVBoxLayout* vL= new QVBoxLayout();
+    QVBoxLayout *vL = new QVBoxLayout();
 
 
     textEdit->setObjectName(QString::fromUtf8("textEdit"));
 /*    textEdit->setMinimumSize(QSize(0, 80));
     textEdit->setMaximumSize(QSize(16777215, 120));*/
-    globTextEdit=textEdit;
+    globTextEdit = textEdit;
     agseterrf(errorPipe);
 
     vL->addWidget(textEdit);
-    vL->setContentsMargins(1,1,1,1);
+    vL->setContentsMargins(1, 1, 1, 1);
 
-    QFrame *fr=new QFrame(dock);
+    QFrame *fr = new QFrame(dock);
     vL->addWidget(fr);
 
-    QPushButton* logNewBtn=new QPushButton(QIcon(":/images/new.png"),"",fr);
-    QPushButton* logSaveBtn=new QPushButton(QIcon(":/images/save.png"),"",fr);
-    QHBoxLayout* consoleLayout = new QHBoxLayout();
+    QPushButton *logNewBtn =
+       new QPushButton(QIcon(":/images/new.png"), "", fr);
+    QPushButton *logSaveBtn =
+       new QPushButton(QIcon(":/images/save.png"), "", fr);
+    QHBoxLayout *consoleLayout = new QHBoxLayout();
     consoleLayout->addWidget(logNewBtn);
-    connect(logNewBtn,SIGNAL(clicked()),this,SLOT(slotNewLog()));
-    connect(logSaveBtn,SIGNAL(clicked()),this,SLOT(slotSaveLog()));
+    connect(logNewBtn, SIGNAL(clicked()), this, SLOT(slotNewLog()));
+    connect(logSaveBtn, SIGNAL(clicked()), this, SLOT(slotSaveLog()));
     consoleLayout->addWidget(logSaveBtn);
     consoleLayout->addStretch();
 
-    consoleLayout->setContentsMargins(1,1,1,1);;
-    consoleLayout->setContentsMargins(1,1,1,1);
+    consoleLayout->setContentsMargins(1, 1, 1, 1);;
+    consoleLayout->setContentsMargins(1, 1, 1, 1);
 
     fr->setLayout(consoleLayout);
 
-    QFrame *mainFrame=new QFrame(dock);
+    QFrame *mainFrame = new QFrame(dock);
     mainFrame->setLayout(vL);
 
 
@@ -107,42 +117,44 @@ void CMainWindow::createConsole()
 
 }
 
-
-
+static char *xtra[] = {
+    "NONE",
+    (char *) 0
+};
 
 CMainWindow::CMainWindow()
 {
 
-        QWidget* centralwidget = new QWidget(this);
-        centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
-        QVBoxLayout* verticalLayout_2 = new QVBoxLayout(centralwidget);
-        verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
-        QVBoxLayout* verticalLayout = new QVBoxLayout();
-        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
-        mdiArea = new QMdiArea(centralwidget);
-        mdiArea->setObjectName(QString::fromUtf8("mdiArea"));
+    QWidget *centralwidget = new QWidget(this);
+    centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
+    QVBoxLayout *verticalLayout_2 = new QVBoxLayout(centralwidget);
+    verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
+    QVBoxLayout *verticalLayout = new QVBoxLayout();
+    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
+    mdiArea = new QMdiArea(centralwidget);
+    mdiArea->setObjectName(QString::fromUtf8("mdiArea"));
 
-        verticalLayout->addWidget(mdiArea);
-       verticalLayout_2->setContentsMargins(1,1,1,1);
-        verticalLayout_2->addLayout(verticalLayout);
-       setCentralWidget(centralwidget);
-       centralwidget->layout()->setContentsMargins(1,1,1,1);
-       prevChild=NULL;
+    verticalLayout->addWidget(mdiArea);
+    verticalLayout_2->setContentsMargins(1, 1, 1, 1);
+    verticalLayout_2->addLayout(verticalLayout);
+    setCentralWidget(centralwidget);
+    centralwidget->layout()->setContentsMargins(1, 1, 1, 1);
+    prevChild = NULL;
 
-       createConsole();
+    createConsole();
 
 
 
 
 
 
-    connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),
-            this, SLOT(slotRefreshMenus()));
+    connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow *)),
+           this, SLOT(slotRefreshMenus()));
     windowMapper = new QSignalMapper(this);
-    connect(windowMapper, SIGNAL(mapped(QWidget*)),
-            this, SLOT(activateChild(QWidget*)));
+    connect(windowMapper, SIGNAL(mapped(QWidget *)),
+           this, SLOT(activateChild(QWidget *)));
 
-    frmSettings= new CFrmSettings();
+    frmSettings = new CFrmSettings();
 
     actions();
     menus();
@@ -153,27 +165,29 @@ CMainWindow::CMainWindow()
     readSettings();
 
     setWindowTitle(tr("GVEdit For Graphviz ver:1.01"));
-    this->resize(1024,900);
-    this->move(0,0);
+    this->resize(1024, 900);
+    this->move(0, 0);
     setUnifiedTitleAndToolBarOnMac(true);
 //    (QComboBox*)frmSettings->findChild<QComboBox*>("cbLayout")
-    QComboBox* cb = (QComboBox*)frmSettings->findChild<QComboBox*>("cbLayout");
-    LoadPlugins(cb,  frmSettings->gvc, "layout", "dot");
-    cb = (QComboBox*)frmSettings->findChild<QComboBox*>("cbExtension");
-    LoadPlugins(cb, frmSettings->gvc, "device", "png");
+    QComboBox *cb =
+       (QComboBox *) frmSettings->findChild < QComboBox * >("cbLayout");
+    dfltLayoutIdx = LoadPlugins(cb, frmSettings->gvc, "layout", 0, "dot");
+    cb = (QComboBox *) frmSettings->findChild <
+       QComboBox * >("cbExtension");
+    dfltRenderIdx =
+       LoadPlugins(cb, frmSettings->gvc, "device", xtra, "png");
     statusBar()->showMessage(tr("Ready"));
     setWindowIcon(QIcon(":/images/icon.png"));
-
 }
 
-void CMainWindow::closeEvent(QCloseEvent *event)
+void CMainWindow::closeEvent(QCloseEvent * event)
 {
     mdiArea->closeAllSubWindows();
     if (mdiArea->currentSubWindow()) {
-        event->ignore();
+       event->ignore();
     } else {
-        writeSettings();
-        event->accept();
+       writeSettings();
+       event->accept();
     }
 }
 
@@ -184,153 +198,152 @@ void CMainWindow::slotNew()
     child->show();
 }
 
-void CMainWindow::addFile (QString fileName)
+void CMainWindow::addFile(QString fileName)
 {
     if (!fileName.isEmpty()) {
-        QMdiSubWindow *existing = findMdiChild(fileName);
-        if (existing) {
-            mdiArea->setActiveSubWindow(existing);
-            return;
-        }
-
-        MdiChild *child = createMdiChild();
-        if (child->loadFile(fileName)) {
-            statusBar()->showMessage(tr("File loaded"), 2000);
-            child->show();
-        } else {
-            child->close();
-        }
+       QMdiSubWindow *existing = findMdiChild(fileName);
+       if (existing) {
+           mdiArea->setActiveSubWindow(existing);
+           return;
+       }
+
+       MdiChild *child = createMdiChild();
+       if (child->loadFile(fileName)) {
+           statusBar()->showMessage(tr("File loaded"), 2000);
+           child->show();
+       } else {
+           child->close();
+       }
     }
 }
 
 void CMainWindow::slotOpen()
 {
     QStringList filters;
-     filters << "*.cpp" << "*.cxx" << "*.cc";
+    filters << "*.cpp" << "*.cxx" << "*.cc";
 
     QFileDialog fd;
 //    fd.setProxyModel(new FileFilterProxyModel());
     fd.setNameFilter("XML (*.xml)");
-   QString fileName =fd.getOpenFileName(this);
+    QString fileName = fd.getOpenFileName(this);
 //    QFileDialog::getOpenFileName(this);
 
-    addFile (fileName);
+    addFile(fileName);
 }
 
 void CMainWindow::slotSave()
 {
     if (activeMdiChild() && activeMdiChild()->save())
-        statusBar()->showMessage(tr("File saved"), 2000);
+       statusBar()->showMessage(tr("File saved"), 2000);
 }
 
 void CMainWindow::slotSaveAs()
 {
     if (activeMdiChild() && activeMdiChild()->saveAs())
-        statusBar()->showMessage(tr("File saved"), 2000);
+       statusBar()->showMessage(tr("File saved"), 2000);
 }
 
 void CMainWindow::slotCut()
 {
     if (activeMdiChild())
-        activeMdiChild()->cut();
+       activeMdiChild()->cut();
 }
 
 void CMainWindow::slotCopy()
 {
     if (activeMdiChild())
-        activeMdiChild()->copy();
+       activeMdiChild()->copy();
 }
 
 void CMainWindow::slotPaste()
 {
     if (activeMdiChild())
-        activeMdiChild()->paste();
+       activeMdiChild()->paste();
 }
 
 void CMainWindow::slotAbout()
 {
-   QMessageBox::about(this, tr("About GVEdit\n"),
-            tr("<b>GVEdit</b> Graph File Editor For Graphviz\n"
-           "Version:1.01"));
+    QMessageBox::about(this, tr("About GVEdit\n"),
+                      tr("<b>GVEdit</b> Graph File Editor For Graphviz\n"
+                         "Version:1.01"));
 }
 
 
 void CMainWindow::slotSettings()
 {
-    if(prevChild !=activeMdiChild())
-    {
+    if (prevChild != activeMdiChild()) {
        QString msg;
        msg.append("working on ");
        msg.append(activeMdiChild()->currentFile());
        msg.append("\n");
-       errorPipe((char*)msg.toAscii().constData());
-       prevChild=activeMdiChild();
+       errorPipe((char *) msg.toAscii().constData());
+       prevChild = activeMdiChild();
     }
     frmSettings->showSettings(activeMdiChild());
 
 }
+
 void CMainWindow::slotRun()
 {
 
-    if(prevChild !=activeMdiChild())
-    {
+    if (prevChild != activeMdiChild()) {
        QString msg;
        msg.append("working on ");
        msg.append(activeMdiChild()->currentFile());
        msg.append("\n");
-       errorPipe((char*)msg.toAscii().constData());
-       prevChild=activeMdiChild();
+       errorPipe((char *) msg.toAscii().constData());
+       prevChild = activeMdiChild();
     }
-    if((activeMdiChild()) && (!activeMdiChild()->firstTime()))
+    if ((activeMdiChild()) && (!activeMdiChild()->firstTime()))
        frmSettings->runSettings(activeMdiChild());
-    if((activeMdiChild()) && (activeMdiChild()->firstTime()))
+    if ((activeMdiChild()) && (activeMdiChild()->firstTime()))
        frmSettings->showSettings(activeMdiChild());
 
 
 }
+
 void CMainWindow::slotNewLog()
 {
     globTextEdit->clear();
 }
+
 void CMainWindow::slotSaveLog()
 {
 
-    if(globTextEdit->toPlainText().trimmed().length()==0)
-    {
-       QMessageBox::warning(this, tr("GvEdit"),tr("Nothing to save!"),QMessageBox::Ok,QMessageBox::Ok);
+    if (globTextEdit->toPlainText().trimmed().length() == 0) {
+       QMessageBox::warning(this, tr("GvEdit"), tr("Nothing to save!"),
+                            QMessageBox::Ok, QMessageBox::Ok);
        return;
 
 
     }
 
     QString fileName = QFileDialog::getSaveFileName(this, tr("Open File"),
-                                                "/",
-                                                 tr("Text File(*.*)"));
- if (!fileName.isEmpty())
- {
-
-    QFile file(fileName);
-    if (!file.open(QFile::WriteOnly | QFile::Text)) {
-        QMessageBox::warning(this, tr("MDI"),
-                             tr("Cannot write file %1:\n%2.")
-                             .arg(fileName)
-                             .arg(file.errorString()));
-        return;
-    }
+                                                   "/",
+                                                   tr("Text File(*.*)"));
+    if (!fileName.isEmpty()) {
+
+       QFile file(fileName);
+       if (!file.open(QFile::WriteOnly | QFile::Text)) {
+           QMessageBox::warning(this, tr("MDI"),
+                                tr("Cannot write file %1:\n%2.")
+                                .arg(fileName)
+                                .arg(file.errorString()));
+           return;
+       }
 
-    QTextStream out(&file);
-    out << globTextEdit->toPlainText();
-    return;
- }
+       QTextStream out(&file);
+       out << globTextEdit->toPlainText();
+       return;
   }
 
 
 }
 
 void CMainWindow::updateFileMenu()
 {
-    if (!activeMdiChild())
-    {
-        saveAct->setEnabled(false);
+    if (!activeMdiChild()) {
+       saveAct->setEnabled(false);
        saveAsAct->setEnabled(false);
        pasteAct->setEnabled(false);
        closeAct->setEnabled(false);
@@ -342,10 +355,8 @@ void CMainWindow::updateFileMenu()
        separatorAct->setVisible(false);
        settingsAct->setEnabled(false);
        layoutAct->setEnabled(false);
-    }
-    else
-    {
-        saveAct->setEnabled(true);
+    } else {
+       saveAct->setEnabled(true);
        saveAsAct->setEnabled(true);
        pasteAct->setEnabled(true);
        closeAct->setEnabled(true);
@@ -358,14 +369,11 @@ void CMainWindow::updateFileMenu()
        settingsAct->setEnabled(true);
        layoutAct->setEnabled(true);
 
-       if(activeMdiChild()->textCursor().hasSelection())
-       {
+       if (activeMdiChild()->textCursor().hasSelection()) {
            cutAct->setEnabled(true);
            copyAct->setEnabled(true);
 
-       }
-       else
-       {
+       } else {
            cutAct->setEnabled(false);
            copyAct->setEnabled(false);
 
@@ -381,6 +389,7 @@ void CMainWindow::slotRefreshMenus()
 {
     updateMenus();
 }
+
 void CMainWindow::updateMenus()
 {
     this->updateFileMenu();
@@ -401,25 +410,26 @@ void CMainWindow::updateWindowMenu()
     mWindow->addAction(previousAct);
     mWindow->addAction(separatorAct);
 
-    QList<QMdiSubWindow *> windows = mdiArea->subWindowList();
+    QList < QMdiSubWindow * >windows = mdiArea->subWindowList();
     separatorAct->setVisible(!windows.isEmpty());
 
     for (int i = 0; i < windows.size(); ++i) {
-       if (windows.at(i)->widget()->inherits("MdiChild"))
-       {
-           MdiChild *child = qobject_cast<MdiChild *>(windows.at(i)->widget());
-            QString text;
+       if (windows.at(i)->widget()->inherits("MdiChild")) {
+           MdiChild *child =
+               qobject_cast < MdiChild * >(windows.at(i)->widget());
+           QString text;
            if (i < 9) {
-               text = tr("&%1 %2").arg(i + 1)
-                               .arg(child->userFriendlyCurrentFile());
+               text = tr("&%1 %2").arg(i + 1)
+                   .arg(child->userFriendlyCurrentFile());
            } else {
                text = tr("%1 %2").arg(i + 1)
-                                 .arg(child->userFriendlyCurrentFile());
+                   .arg(child->userFriendlyCurrentFile());
            }
-           QAction *action  = mWindow->addAction(text);
+           QAction *action = mWindow->addAction(text);
            action->setCheckable(true);
-           action ->setChecked(child == activeMdiChild());
-           connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
+           action->setChecked(child == activeMdiChild());
+           connect(action, SIGNAL(triggered()), windowMapper,
+                   SLOT(map()));
            windowMapper->setMapping(action, windows.at(i));
        }
     }
@@ -428,14 +438,17 @@ void CMainWindow::updateWindowMenu()
 MdiChild *CMainWindow::createMdiChild()
 {
     MdiChild *child = new MdiChild;
-    child->parentFrm=this;
-    QMdiSubWindow* s=mdiArea->addSubWindow(child);
-    s->resize(800,600);
-    s->move(mdiArea->subWindowList().count()*5,mdiArea->subWindowList().count()*5);
-    connect(child, SIGNAL(copyAvailable(bool)),
-            cutAct, SLOT(setEnabled(bool)));
-    connect(child, SIGNAL(copyAvailable(bool)),
-            copyAct, SLOT(setEnabled(bool)));
+    child->parentFrm = this;
+    QMdiSubWindow *s = mdiArea->addSubWindow(child);
+    s->resize(800, 600);
+    s->move(mdiArea->subWindowList().count() * 5,
+           mdiArea->subWindowList().count() * 5);
+    connect(child, SIGNAL(copyAvailable(bool)), cutAct,
+           SLOT(setEnabled(bool)));
+    connect(child, SIGNAL(copyAvailable(bool)), copyAct,
+           SLOT(setEnabled(bool)));
+    child->layoutIdx = dfltLayoutIdx;
+    child->renderIdx = dfltRenderIdx;
 
     return child;
 }
@@ -447,7 +460,8 @@ void CMainWindow::actions()
     newAct->setStatusTip(tr("Create a new file"));
     connect(newAct, SIGNAL(triggered()), this, SLOT(slotNew()));
 
-    openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
+    openAct =
+       new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
     openAct->setShortcuts(QKeySequence::Open);
     openAct->setStatusTip(tr("Open an existing file"));
     connect(openAct, SIGNAL(triggered()), this, SLOT(slotOpen()));
@@ -469,28 +483,38 @@ void CMainWindow::actions()
     connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
     cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);
     cutAct->setShortcuts(QKeySequence::Cut);
-    cutAct->setStatusTip(tr("Cut the current selection's contents to the ""clipboard"));
+    cutAct->
+       setStatusTip(tr
+                    ("Cut the current selection's contents to the "
+                     "clipboard"));
     connect(cutAct, SIGNAL(triggered()), this, SLOT(slotCut()));
 
     copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this);
     copyAct->setShortcuts(QKeySequence::Copy);
-    copyAct->setStatusTip(tr("Copy the current selection's contents to the "
-                             "clipboard"));
+    copyAct->
+       setStatusTip(tr
+                    ("Copy the current selection's contents to the "
+                     "clipboard"));
     connect(copyAct, SIGNAL(triggered()), this, SLOT(slotCopy()));
 
-    pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
+    pasteAct =
+       new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
     pasteAct->setShortcuts(QKeySequence::Paste);
-    pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
-                              "selection"));
+    pasteAct->
+       setStatusTip(tr
+                    ("Paste the clipboard's contents into the current "
+                     "selection"));
     connect(pasteAct, SIGNAL(triggered()), this, SLOT(slotPaste()));
 
     closeAct = new QAction(tr("Cl&ose"), this);
     closeAct->setStatusTip(tr("Close the active window"));
-    connect(closeAct, SIGNAL(triggered()),mdiArea, SLOT(closeActiveSubWindow()));
+    connect(closeAct, SIGNAL(triggered()), mdiArea,
+           SLOT(closeActiveSubWindow()));
 
     closeAllAct = new QAction(tr("Close &All"), this);
     closeAllAct->setStatusTip(tr("Close all the windows"));
-    connect(closeAllAct, SIGNAL(triggered()),mdiArea, SLOT(closeAllSubWindows()));
+    connect(closeAllAct, SIGNAL(triggered()), mdiArea,
+           SLOT(closeAllSubWindows()));
 
     tileAct = new QAction(tr("&Tile"), this);
     tileAct->setStatusTip(tr("Tile the windows"));
@@ -498,17 +522,20 @@ void CMainWindow::actions()
 
     cascadeAct = new QAction(tr("&Cascade"), this);
     cascadeAct->setStatusTip(tr("Cascade the windows"));
-    connect(cascadeAct, SIGNAL(triggered()), mdiArea, SLOT(cascadeSubWindows()));
+    connect(cascadeAct, SIGNAL(triggered()), mdiArea,
+           SLOT(cascadeSubWindows()));
 
     nextAct = new QAction(tr("Ne&xt"), this);
     nextAct->setShortcuts(QKeySequence::NextChild);
     nextAct->setStatusTip(tr("Move the focus to the next window"));
-    connect(nextAct, SIGNAL(triggered()),mdiArea, SLOT(activateNextSubWindow()));
+    connect(nextAct, SIGNAL(triggered()), mdiArea,
+           SLOT(activateNextSubWindow()));
 
     previousAct = new QAction(tr("Pre&vious"), this);
     previousAct->setShortcuts(QKeySequence::PreviousChild);
     previousAct->setStatusTip(tr("Move the focus to the previous window"));
-    connect(previousAct, SIGNAL(triggered()),mdiArea, SLOT(activatePreviousSubWindow()));
+    connect(previousAct, SIGNAL(triggered()), mdiArea,
+           SLOT(activatePreviousSubWindow()));
 
     separatorAct = new QAction(this);
     separatorAct->setSeparator(true);
@@ -519,7 +546,8 @@ void CMainWindow::actions()
 
 
 
-    settingsAct = new QAction(QIcon(":/images/settings.png"),tr("Settings"), this);
+    settingsAct =
+       new QAction(QIcon(":/images/settings.png"), tr("Settings"), this);
     settingsAct->setStatusTip(tr("Show Graphviz Settings"));
     connect(settingsAct, SIGNAL(triggered()), this, SLOT(slotSettings()));
     settingsAct->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F5));
@@ -527,7 +555,7 @@ void CMainWindow::actions()
 
 
 
-    layoutAct = new QAction(QIcon(":/images/run.png"),tr("Layout"), this);
+    layoutAct = new QAction(QIcon(":/images/run.png"), tr("Layout"), this);
     layoutAct->setStatusTip(tr("Layout the active graph"));
     connect(layoutAct, SIGNAL(triggered()), this, SLOT(slotRun()));
     layoutAct->setShortcut(QKeySequence(Qt::Key_F5));
@@ -541,7 +569,7 @@ void CMainWindow::menus()
     mFile = menuBar()->addMenu(tr("&File"));
     mEdit = menuBar()->addMenu(tr("&Edit"));
     mWindow = menuBar()->addMenu(tr("&Window"));
-    mGraph =  menuBar()->addMenu (tr("&Graph"));
+    mGraph = menuBar()->addMenu(tr("&Graph"));
     mHelp = menuBar()->addMenu(tr("&Help"));
 
 
@@ -563,7 +591,8 @@ void CMainWindow::menus()
     loadPlugins();
 
     updateWindowMenu();
-    connect(mWindow, SIGNAL(aboutToShow()), this, SLOT(slotRefreshMenus()));
+    connect(mWindow, SIGNAL(aboutToShow()), this,
+           SLOT(slotRefreshMenus()));
     mHelp->addAction(aboutAct);
 }
 
@@ -604,33 +633,33 @@ void CMainWindow::writeSettings()
 
 MdiChild *CMainWindow::activeMdiChild()
 {
-    if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
-    {
-       if(activeSubWindow->widget()->inherits("MdiChild"))
-           return qobject_cast<MdiChild *>(activeSubWindow->widget());
-        else
-           return qobject_cast <ImageViewer *> (activeSubWindow->widget())->graphWindow;
+    if (QMdiSubWindow * activeSubWindow = mdiArea->activeSubWindow()) {
+       if (activeSubWindow->widget()->inherits("MdiChild"))
+           return qobject_cast < MdiChild * >(activeSubWindow->widget());
+       else
+           return qobject_cast <
+               ImageViewer * >(activeSubWindow->widget())->graphWindow;
 
     }
     return 0;
 }
 
-QMdiSubWindow *CMainWindow::findMdiChild(const QString &fileName)
+QMdiSubWindow *CMainWindow::findMdiChild(const QString & fileName)
 {
     QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
 
-    foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
-       if (window->widget()->inherits("MdiChild"))
-       {
+    foreach(QMdiSubWindow * window, mdiArea->subWindowList()) {
+       if (window->widget()->inherits("MdiChild")) {
 
-           MdiChild *mdiChild = qobject_cast<MdiChild *>(window->widget());
+           MdiChild *mdiChild =
+               qobject_cast < MdiChild * >(window->widget());
            if (mdiChild->currentFile() == canonicalFilePath)
                return window;
-       }
-       else
-       {
+       } else {
 
-           MdiChild *mdiChild = qobject_cast<ImageViewer *>(window->widget())->graphWindow;
+           MdiChild *mdiChild =
+               qobject_cast <
+               ImageViewer * >(window->widget())->graphWindow;
            if (mdiChild->currentFile() == canonicalFilePath)
                return window;
        }
@@ -641,14 +670,14 @@ QMdiSubWindow *CMainWindow::findMdiChild(const QString &fileName)
     return 0;
 }
 
-void CMainWindow::activateChild(QWidget *window)
+void CMainWindow::activateChild(QWidget * window)
 {
     if (!window)
-        return;
-    mdiArea->setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window));
+       return;
+    mdiArea->setActiveSubWindow(qobject_cast < QMdiSubWindow * >(window));
 }
+
 void CMainWindow::loadPlugins()
 {
 
 }
-
index 73847b056dbbc2ac03fb8c2048c3f9457889e512..5aa758d3b586f2e518e75ec71f3fe6db098acb35 100644 (file)
@@ -79,9 +79,7 @@ private:
     MdiChild* prevChild;
     QMdiSubWindow *findMdiChild(const QString &fileName);
     QSignalMapper *windowMapper;
-
-
-
+    int dfltRenderIdx, dfltLayoutIdx;
 
     QToolBar *tbFile;
     QToolBar *tbEdit;
index 17bfd201a4e8ff89abd98a3e5ebff26cdb6b2110..5e08f2c62f36791e59e24c5a45856bb3e23fd2b8 100644 (file)
@@ -21,12 +21,12 @@ MdiChild::MdiChild()
 {
     setAttribute(Qt::WA_DeleteOnClose);
     isUntitled = true;
-    layoutIdx=0;
-    renderIdx=0;
-    preview=true;
-    applyCairo=false;
-    previewFrm=NULL;
-    settingsSet=false;
+    layoutIdx = 0;
+    renderIdx = 0;
+    preview = true;
+    applyCairo = false;
+    previewFrm = NULL;
+    settingsSet = false;
 }
 
 void MdiChild::newFile()
@@ -38,18 +38,18 @@ void MdiChild::newFile()
     setWindowTitle(curFile + "[*]");
 
     connect(document(), SIGNAL(contentsChanged()),
-            this, SLOT(documentWasModified()));
+           this, SLOT(documentWasModified()));
 }
 
-bool MdiChild::loadFile(const QString &fileName)
+bool MdiChild::loadFile(const QString & fileName)
 {
     QFile file(fileName);
     if (!file.open(QFile::ReadOnly | QFile::Text)) {
-        QMessageBox::warning(this, tr("MDI"),
-                             tr("Cannot read file %1:\n%2.")
-                             .arg(fileName)
-                             .arg(file.errorString()));
-        return false;
+       QMessageBox::warning(this, tr("MDI"),
+                            tr("Cannot read file %1:\n%2.")
+                            .arg(fileName)
+                            .arg(file.errorString()));
+       return false;
     }
 
     QTextStream in(&file);
@@ -60,7 +60,7 @@ bool MdiChild::loadFile(const QString &fileName)
     setCurrentFile(fileName);
 
     connect(document(), SIGNAL(contentsChanged()),
-            this, SLOT(documentWasModified()));
+           this, SLOT(documentWasModified()));
 
     return true;
 }
@@ -68,31 +68,31 @@ bool MdiChild::loadFile(const QString &fileName)
 bool MdiChild::save()
 {
     if (isUntitled) {
-        return saveAs();
+       return saveAs();
     } else {
-        return saveFile(curFile);
+       return saveFile(curFile);
     }
 }
 
 bool MdiChild::saveAs()
 {
     QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
-                                                    curFile);
+                                                   curFile);
     if (fileName.isEmpty())
-        return false;
+       return false;
 
     return saveFile(fileName);
 }
 
-bool MdiChild::saveFile(const QString &fileName)
+bool MdiChild::saveFile(const QString & fileName)
 {
     QFile file(fileName);
     if (!file.open(QFile::WriteOnly | QFile::Text)) {
-        QMessageBox::warning(this, tr("MDI"),
-                             tr("Cannot write file %1:\n%2.")
-                             .arg(fileName)
-                             .arg(file.errorString()));
-        return false;
+       QMessageBox::warning(this, tr("MDI"),
+                            tr("Cannot write file %1:\n%2.")
+                            .arg(fileName)
+                            .arg(file.errorString()));
+       return false;
     }
 
     QTextStream out(&file);
@@ -110,12 +110,12 @@ QString MdiChild::userFriendlyCurrentFile()
     return strippedName(curFile);
 }
 
-void MdiChild::closeEvent(QCloseEvent *event)
+void MdiChild::closeEvent(QCloseEvent * event)
 {
     if (maybeSave()) {
-        event->accept();
+       event->accept();
     } else {
-        event->ignore();
+       event->ignore();
     }
 }
 
@@ -128,21 +128,21 @@ bool MdiChild::maybeSave()
 {
     if (document()->isModified()) {
        QMessageBox::StandardButton ret;
-        ret = QMessageBox::warning(this, tr("MDI"),
-                     tr("'%1' has been modified.\n"
-                        "Do you want to save your changes?")
-                     .arg(userFriendlyCurrentFile()),
-                     QMessageBox::Save | QMessageBox::Discard
-                    | QMessageBox::Cancel);
-        if (ret == QMessageBox::Save)
-            return save();
-        else if (ret == QMessageBox::Cancel)
-            return false;
+       ret = QMessageBox::warning(this, tr("MDI"),
+                                  tr("'%1' has been modified.\n"
+                                     "Do you want to save your changes?")
+                                  .arg(userFriendlyCurrentFile()),
+                                  QMessageBox::Save | QMessageBox::Discard
+                                  | QMessageBox::Cancel);
+       if (ret == QMessageBox::Save)
+           return save();
+       else if (ret == QMessageBox::Cancel)
+           return false;
     }
     return true;
 }
 
-void MdiChild::setCurrentFile(const QString &fileName)
+void MdiChild::setCurrentFile(const QString & fileName)
 {
     curFile = QFileInfo(fileName).canonicalFilePath();
     isUntitled = false;
@@ -151,32 +151,32 @@ void MdiChild::setCurrentFile(const QString &fileName)
     setWindowTitle(userFriendlyCurrentFile() + "[*]");
 }
 
-QString MdiChild::strippedName(const QString &fullFileName)
+QString MdiChild::strippedName(const QString & fullFileName)
 {
     return QFileInfo(fullFileName).fileName();
 }
 
 bool MdiChild::loadPreview(QString fileName)
 {
-    if (!this->previewFrm)
-    {
-       previewFrm=new ImageViewer();
-       previewFrm->graphWindow=this;
-       QMdiSubWindow* s=parentFrm->mdiArea->addSubWindow(previewFrm);
+    if (!this->previewFrm) {
+       previewFrm = new ImageViewer();
+       previewFrm->graphWindow = this;
+       QMdiSubWindow *s = parentFrm->mdiArea->addSubWindow(previewFrm);
 
-       s->resize(600,400);
-       s->move(parentFrm->mdiArea->subWindowList().count()*5,parentFrm->mdiArea->subWindowList().count()*5);
-       previewFrm->subWindowRef=s;
+       s->resize(600, 400);
+       s->move(parentFrm->mdiArea->subWindowList().count() * 5,
+               parentFrm->mdiArea->subWindowList().count() * 5);
+       previewFrm->subWindowRef = s;
 
     }
-    bool rv=previewFrm->open(fileName);
-    if(rv)
+    bool rv = previewFrm->open(fileName);
+    if (rv)
        previewFrm->show();
     return rv;
 
 }
+
 bool MdiChild::firstTime()
 {
     return settingsSet;
 }
-