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
#define WIDGET(t,f) ((t*)findChild<t *>(#f))
typedef struct {
- const char* data;
+ 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;
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 char* ptr;
- char* optr;
+ 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;
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;
activeWindow = NULL;
QString path;
#ifndef WIN32
- char* s = 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());
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;
}
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;
}
-
-
-
bool loadRenderers();
void refreshContent();
void saveContent();
+ void doPreview(QString);
void setActiveWindow(MdiChild* m);
bool loadGraph(MdiChild* m);
bool createLayout();
#include "imageviewer.h"
#include "mdichild.h"
-extern int errorPipe(char* errMsg);
+extern int errorPipe(char *errMsg);
//! [0]
setWindowIcon(QIcon(":/images/icon.png"));
}
+
//! [0]
//! [1]
//! [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());
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);
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);
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()));
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();
// 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());
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();
}
#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 char* cmd;
+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";
if (optopt == '?')
usage(0);
else
- errout << cmd << " : option -" << ((char)optopt) << " unrecognized - ignored\n" << flush;
+ errout << cmd << " : option -" << ((char) optopt) <<
+ " unrecognized - ignored\n" << flush;
break;
}
}
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();
#include <string.h>
-QTextEdit* globTextEdit;
+QTextEdit *globTextEdit;
-int errorPipe(char* errMsg)
+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);
- QTextEdit* textEdit = 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);
}
-
-
+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();
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();
}
}
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);
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);
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);
{
updateMenus();
}
+
void CMainWindow::updateMenus()
{
this->updateFileMenu();
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));
}
}
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;
}
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()));
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"));
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);
- 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));
- 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));
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"));
loadPlugins();
updateWindowMenu();
- connect(mWindow, SIGNAL(aboutToShow()), this, SLOT(slotRefreshMenus()));
+ connect(mWindow, SIGNAL(aboutToShow()), this,
+ SLOT(slotRefreshMenus()));
mHelp->addAction(aboutAct);
}
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;
}
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()
{
}
-
MdiChild* prevChild;
QMdiSubWindow *findMdiChild(const QString &fileName);
QSignalMapper *windowMapper;
-
-
-
+ int dfltRenderIdx, dfltLayoutIdx;
QToolBar *tbFile;
QToolBar *tbEdit;
{
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()
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);
setCurrentFile(fileName);
connect(document(), SIGNAL(contentsChanged()),
- this, SLOT(documentWasModified()));
+ this, SLOT(documentWasModified()));
return true;
}
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);
return strippedName(curFile);
}
-void MdiChild::closeEvent(QCloseEvent *event)
+void MdiChild::closeEvent(QCloseEvent * event)
{
if (maybeSave()) {
- event->accept();
+ event->accept();
} else {
- event->ignore();
+ event->ignore();
}
}
{
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;
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;
}
-