25 QString::fromUtf8(errMsg));
30 for (
int i = 0; i < count; i++)
36 const QStringList &more, std::string_view prefer) {
39 std::optional<int> idx;
42 for (
int id = 0;
id < count;
id++) {
43 cb.addItem(QString::fromUtf8(lp[
id]));
44 if (!idx.has_value() && prefer == lp[
id])
53 cb.setCurrentIndex(*idx);
55 return idx.value_or(0);
58void CMainWindow::createConsole() {
59 QDockWidget *dock =
new QDockWidget(tr(
"Output Console"),
nullptr);
60 QTextEdit *textEdit =
new QTextEdit(dock);
62 dock->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
63 addDockWidget(Qt::BottomDockWidgetArea, dock);
64 QVBoxLayout *vL =
new QVBoxLayout();
66 textEdit->setObjectName(QStringLiteral(
"textEdit"));
70 vL->addWidget(textEdit);
71 vL->setContentsMargins(1, 1, 1, 1);
73 QFrame *fr =
new QFrame(dock);
76 QPushButton *logNewBtn =
77 new QPushButton(QIcon(QStringLiteral(
":/images/new.png")), {}, fr);
78 QPushButton *logSaveBtn =
79 new QPushButton(QIcon(QStringLiteral(
":/images/save.png")), {}, fr);
80 QHBoxLayout *consoleLayout =
new QHBoxLayout();
81 consoleLayout->addWidget(logNewBtn);
82 connect(logNewBtn, &QPushButton::clicked,
this, &CMainWindow::slotNewLog);
83 connect(logSaveBtn, &QPushButton::clicked,
this, &CMainWindow::slotSaveLog);
84 consoleLayout->addWidget(logSaveBtn);
85 consoleLayout->addStretch();
87 consoleLayout->setContentsMargins(1, 1, 1, 1);
89 fr->setLayout(consoleLayout);
91 QFrame *mainFrame =
new QFrame(dock);
92 mainFrame->setLayout(vL);
94 dock->setWidget(mainFrame);
97static const QStringList
xtra = {QStringLiteral(
"NONE")};
101 QWidget *centralwidget =
new QWidget(
this);
102 centralwidget->setObjectName(QStringLiteral(
"centralwidget"));
103 QVBoxLayout *verticalLayout_2 =
new QVBoxLayout(centralwidget);
104 verticalLayout_2->setObjectName(QStringLiteral(
"verticalLayout_2"));
105 QVBoxLayout *verticalLayout =
new QVBoxLayout();
106 verticalLayout->setObjectName(QStringLiteral(
"verticalLayout"));
107 mdiArea =
new QMdiArea(centralwidget);
108 mdiArea->setObjectName(QStringLiteral(
"mdiArea"));
110 verticalLayout->addWidget(
mdiArea);
111 verticalLayout_2->setContentsMargins(1, 1, 1, 1);
112 verticalLayout_2->addLayout(verticalLayout);
113 setCentralWidget(centralwidget);
114 centralwidget->layout()->setContentsMargins(1, 1, 1, 1);
119 connect(
mdiArea, &QMdiArea::subWindowActivated,
this,
120 &CMainWindow::slotRefreshMenus);
132 setWindowTitle(tr(
"GVEdit"));
133 this->resize(1024, 900);
135 setUnifiedTitleAndToolBarOnMac(
true);
137 frmSettings->findChild<QComboBox *>(QStringLiteral(
"cbLayout"));
138 dfltLayoutIdx =
LoadPlugins(*cb, frmSettings->
gvc,
"layout", {},
"dot");
139 cb = frmSettings->findChild<QComboBox *>(QStringLiteral(
"cbExtension"));
141 statusBar()->showMessage(tr(
"Ready"));
142 setWindowIcon(QIcon(QStringLiteral(
":/images/icon.png")));
144 for (
const QString &file : files) {
151 if (
mdiArea->currentSubWindow()) {
159void CMainWindow::slotNew() {
167 QMdiSubWindow *existing = findMdiChild(
fileName);
169 mdiArea->setActiveSubWindow(existing);
175 statusBar()->showMessage(tr(
"File loaded"), 2000);
184void CMainWindow::slotOpen() {
186 QStringLiteral(
"*.cpp"),
187 QStringLiteral(
"*.cxx"),
188 QStringLiteral(
"*.cc"),
192 fd.setNameFilter(QStringLiteral(
"XML (*.xml)"));
193 QString
fileName = fd.getOpenFileName(
this);
198void CMainWindow::slotSave() {
199 if (activeMdiChild() && activeMdiChild()->save())
200 statusBar()->showMessage(tr(
"File saved"), 2000);
203void CMainWindow::slotSaveAs() {
204 if (activeMdiChild() && activeMdiChild()->saveAs())
205 statusBar()->showMessage(tr(
"File saved"), 2000);
208void CMainWindow::slotCut() {
209 if (activeMdiChild())
210 activeMdiChild()->cut();
213void CMainWindow::slotCopy() {
214 if (activeMdiChild())
215 activeMdiChild()->copy();
218void CMainWindow::slotPaste() {
219 if (activeMdiChild())
220 activeMdiChild()->paste();
223void CMainWindow::slotAbout() {
224 QString abs(tr(
"<b>GVEdit</b> Graph File Editor For Graphviz"
226 "Graphviz version: "));
229 QMessageBox::about(
this, tr(
"About GVEdit"), abs);
232void CMainWindow::setChild() {
233 if (prevChild != activeMdiChild()) {
235 QStringLiteral(
"working on %1\n").arg(activeMdiChild()->currentFile());
237 prevChild = activeMdiChild();
241void CMainWindow::slotSettings() {
246void CMainWindow::slotRun(
MdiChild *m) {
255void CMainWindow::slotNewLog() {
globTextEdit->clear(); }
257void CMainWindow::slotSaveLog() {
260 QMessageBox::warning(
this, tr(
"GvEdit"), tr(
"Nothing to save!"),
261 QMessageBox::Ok, QMessageBox::Ok);
265 QString
fileName = QFileDialog::getSaveFileName(
266 this, tr(
"Open File"), QStringLiteral(
"/"), tr(
"Text File(*.*)"));
270 if (!file.open(QFile::WriteOnly | QFile::Text)) {
271 QMessageBox::warning(
this, tr(
"MDI"),
272 tr(
"Cannot write file %1:\n%2.")
274 .arg(file.errorString()));
278 QTextStream
out(&file);
283void CMainWindow::updateFileMenu() {
284 if (!activeMdiChild()) {
285 saveAct->setEnabled(
false);
286 saveAsAct->setEnabled(
false);
287 pasteAct->setEnabled(
false);
288 closeAct->setEnabled(
false);
289 closeAllAct->setEnabled(
false);
290 tileAct->setEnabled(
false);
291 cascadeAct->setEnabled(
false);
292 nextAct->setEnabled(
false);
293 previousAct->setEnabled(
false);
294 separatorAct->setVisible(
false);
295 settingsAct->setEnabled(
false);
296 layoutAct->setEnabled(
false);
298 saveAct->setEnabled(
true);
299 saveAsAct->setEnabled(
true);
300 pasteAct->setEnabled(
true);
301 closeAct->setEnabled(
true);
302 closeAllAct->setEnabled(
true);
303 tileAct->setEnabled(
true);
304 cascadeAct->setEnabled(
true);
305 nextAct->setEnabled(
true);
306 previousAct->setEnabled(
true);
307 separatorAct->setVisible(
true);
308 settingsAct->setEnabled(
true);
309 layoutAct->setEnabled(
true);
311 if (activeMdiChild()->textCursor().hasSelection()) {
312 cutAct->setEnabled(
true);
313 copyAct->setEnabled(
true);
316 cutAct->setEnabled(
false);
317 copyAct->setEnabled(
false);
322void CMainWindow::slotRefreshMenus() { updateMenus(); }
324void CMainWindow::updateMenus() {
325 this->updateFileMenu();
326 this->updateWindowMenu();
329void CMainWindow::updateWindowMenu() {
331 mWindow->addAction(closeAct);
332 mWindow->addAction(closeAllAct);
333 mWindow->addSeparator();
334 mWindow->addAction(tileAct);
335 mWindow->addAction(cascadeAct);
336 mWindow->addSeparator();
337 mWindow->addAction(nextAct);
338 mWindow->addAction(previousAct);
339 mWindow->addAction(separatorAct);
341 QList<QMdiSubWindow *> windows =
mdiArea->subWindowList();
342 separatorAct->setVisible(!windows.isEmpty());
344 for (
int i = 0; i < windows.size(); ++i) {
345 QMdiSubWindow *window = windows.at(i);
346 if (window->widget()->inherits(
"MdiChild")) {
347 MdiChild *child = qobject_cast<MdiChild *>(window->widget());
354 QAction *action = mWindow->addAction(text);
355 action->setCheckable(
true);
356 action->setChecked(child == activeMdiChild());
357 connect(action, &QAction::triggered,
this,
358 [
this, window] { activateChild(window); });
363MdiChild *CMainWindow::createMdiChild() {
366 QMdiSubWindow *
s =
mdiArea->addSubWindow(child);
368 s->move(
mdiArea->subWindowList().count() * 5,
369 mdiArea->subWindowList().count() * 5);
370 connect(child, &MdiChild::copyAvailable, cutAct, &QAction::setEnabled);
371 connect(child, &MdiChild::copyAvailable, copyAct, &QAction::setEnabled);
378void CMainWindow::actions() {
380 new QAction(QIcon(QStringLiteral(
":/images/new.png")), tr(
"&New"),
this);
381 newAct->setShortcuts(QKeySequence::New);
382 newAct->setStatusTip(tr(
"Create a new file"));
383 connect(newAct, &QAction::triggered,
this, &CMainWindow::slotNew);
385 openAct =
new QAction(QIcon(QStringLiteral(
":/images/open.png")),
386 tr(
"&Open..."),
this);
387 openAct->setShortcuts(QKeySequence::Open);
388 openAct->setStatusTip(tr(
"Open an existing file"));
389 connect(openAct, &QAction::triggered,
this, &CMainWindow::slotOpen);
391 saveAct =
new QAction(QIcon(QStringLiteral(
":/images/save.png")), tr(
"&Save"),
393 saveAct->setShortcuts(QKeySequence::Save);
394 saveAct->setStatusTip(tr(
"Save the document to disk"));
395 connect(saveAct, &QAction::triggered,
this, &CMainWindow::slotSave);
397 saveAsAct =
new QAction(tr(
"Save &As..."),
this);
398 saveAsAct->setShortcuts(QKeySequence::SaveAs);
399 saveAsAct->setStatusTip(tr(
"Save the document under a new name"));
400 connect(saveAsAct, &QAction::triggered,
this, &CMainWindow::slotSaveAs);
402 exitAct =
new QAction(tr(
"E&xit"),
this);
403 exitAct->setShortcuts(QKeySequence::Quit);
404 exitAct->setStatusTip(tr(
"Exit the application"));
405 connect(exitAct, &QAction::triggered, qApp, &QApplication::closeAllWindows);
408 new QAction(QIcon(QStringLiteral(
":/images/cut.png")), tr(
"Cu&t"),
this);
409 cutAct->setShortcuts(QKeySequence::Cut);
410 cutAct->setStatusTip(tr(
"Cut the current selection's contents to the "
412 connect(cutAct, &QAction::triggered,
this, &CMainWindow::slotCut);
414 copyAct =
new QAction(QIcon(QStringLiteral(
":/images/copy.png")), tr(
"&Copy"),
416 copyAct->setShortcuts(QKeySequence::Copy);
417 copyAct->setStatusTip(tr(
"Copy the current selection's contents to the "
419 connect(copyAct, &QAction::triggered,
this, &CMainWindow::slotCopy);
421 pasteAct =
new QAction(QIcon(QStringLiteral(
":/images/paste.png")),
423 pasteAct->setShortcuts(QKeySequence::Paste);
424 pasteAct->setStatusTip(tr(
"Paste the clipboard's contents into the current "
426 connect(pasteAct, &QAction::triggered,
this, &CMainWindow::slotPaste);
428 closeAct =
new QAction(tr(
"Cl&ose"),
this);
429 closeAct->setStatusTip(tr(
"Close the active window"));
430 connect(closeAct, &QAction::triggered,
mdiArea,
431 &QMdiArea::closeActiveSubWindow);
433 closeAllAct =
new QAction(tr(
"Close &All"),
this);
434 closeAllAct->setStatusTip(tr(
"Close all the windows"));
435 connect(closeAllAct, &QAction::triggered,
mdiArea,
436 &QMdiArea::closeAllSubWindows);
438 tileAct =
new QAction(tr(
"&Tile"),
this);
439 tileAct->setStatusTip(tr(
"Tile the windows"));
440 connect(tileAct, &QAction::triggered,
mdiArea, &QMdiArea::tileSubWindows);
442 cascadeAct =
new QAction(tr(
"&Cascade"),
this);
443 cascadeAct->setStatusTip(tr(
"Cascade the windows"));
444 connect(cascadeAct, &QAction::triggered,
mdiArea,
445 &QMdiArea::cascadeSubWindows);
447 nextAct =
new QAction(tr(
"Ne&xt"),
this);
448 nextAct->setShortcuts(QKeySequence::NextChild);
449 nextAct->setStatusTip(tr(
"Move the focus to the next window"));
450 connect(nextAct, &QAction::triggered,
mdiArea,
451 &QMdiArea::activateNextSubWindow);
453 previousAct =
new QAction(tr(
"Pre&vious"),
this);
454 previousAct->setShortcuts(QKeySequence::PreviousChild);
455 previousAct->setStatusTip(tr(
"Move the focus to the previous window"));
456 connect(previousAct, &QAction::triggered,
mdiArea,
457 &QMdiArea::activatePreviousSubWindow);
459 separatorAct =
new QAction(
this);
460 separatorAct->setSeparator(
true);
462 aboutAct =
new QAction(tr(
"&About"),
this);
463 aboutAct->setStatusTip(tr(
"Show the application's About box"));
464 connect(aboutAct, &QAction::triggered,
this, &CMainWindow::slotAbout);
466 settingsAct =
new QAction(QIcon(QStringLiteral(
":/images/settings.png")),
467 tr(
"Settings"),
this);
468 settingsAct->setStatusTip(tr(
"Show Graphviz Settings"));
469 connect(settingsAct, &QAction::triggered,
this, &CMainWindow::slotSettings);
470 settingsAct->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_F5));
472 layoutAct =
new QAction(QIcon(QStringLiteral(
":/images/run.png")),
474 layoutAct->setStatusTip(tr(
"Layout the active graph"));
475 connect(layoutAct, &QAction::triggered,
this, [
this] { slotRun(); });
476 layoutAct->setShortcut(QKeySequence(Qt::Key_F5));
479void CMainWindow::menus() {
480 mFile = menuBar()->addMenu(tr(
"&File"));
481 mEdit = menuBar()->addMenu(tr(
"&Edit"));
482 mWindow = menuBar()->addMenu(tr(
"&Window"));
483 mGraph = menuBar()->addMenu(tr(
"&Graph"));
484 mHelp = menuBar()->addMenu(tr(
"&Help"));
486 mFile->addAction(newAct);
487 mFile->addAction(openAct);
488 mFile->addAction(saveAct);
489 mFile->addAction(saveAsAct);
490 mFile->addSeparator();
492 mFile->addAction(exitAct);
494 mEdit->addAction(cutAct);
495 mEdit->addAction(copyAct);
496 mEdit->addAction(pasteAct);
498 mGraph->addAction(settingsAct);
499 mGraph->addAction(layoutAct);
500 mGraph->addSeparator();
503 connect(mWindow, &QMenu::aboutToShow,
this, &CMainWindow::slotRefreshMenus);
504 mHelp->addAction(aboutAct);
507void CMainWindow::toolBars() {
508 tbFile = addToolBar(tr(
"File"));
509 tbFile->addAction(newAct);
510 tbFile->addAction(openAct);
511 tbFile->addAction(saveAct);
513 tbEdit = addToolBar(tr(
"Edit"));
514 tbEdit->addAction(cutAct);
515 tbEdit->addAction(copyAct);
516 tbEdit->addAction(pasteAct);
518 tbGraph = addToolBar(tr(
"Graph"));
519 tbGraph->addAction(settingsAct);
520 tbGraph->addAction(layoutAct);
523void CMainWindow::readSettings() {
526 QSettings settings(QStringLiteral(
"Graphviz"), QStringLiteral(
"gvedit"));
527 if (settings.contains(QStringLiteral(
"pos")) &&
528 settings.contains(QStringLiteral(
"size"))) {
530 settings.value(QStringLiteral(
"pos"), QPoint(200, 200)).toPoint();
532 settings.value(QStringLiteral(
"size"), QSize(400, 400)).toSize();
540 QSettings settings(QStringLiteral(
"Trolltech"),
541 QStringLiteral(
"MDI Example"));
543 settings.value(QStringLiteral(
"pos"), QPoint(200, 200)).toPoint();
544 QSize size = settings.value(QStringLiteral(
"size"), QSize(400, 400)).toSize();
549void CMainWindow::writeSettings() {
550 QSettings settings(QStringLiteral(
"Graphviz"), QStringLiteral(
"gvedit"));
551 settings.setValue(QStringLiteral(
"pos"), pos());
552 settings.setValue(QStringLiteral(
"size"), size());
555MdiChild *CMainWindow::activeMdiChild() {
556 if (QMdiSubWindow *activeSubWindow =
mdiArea->activeSubWindow()) {
557 if (activeSubWindow->widget()->inherits(
"MdiChild"))
558 return qobject_cast<MdiChild *>(activeSubWindow->widget());
559 return qobject_cast<ImageViewer *>(activeSubWindow->widget())->graphWindow;
564QMdiSubWindow *CMainWindow::findMdiChild(
const QString &
fileName) {
565 QString canonicalFilePath = QFileInfo(
fileName).canonicalFilePath();
567 foreach (QMdiSubWindow *window,
mdiArea->subWindowList()) {
568 if (window->widget()->inherits(
"MdiChild")) {
570 MdiChild *mdiChild = qobject_cast<MdiChild *>(window->widget());
576 qobject_cast<ImageViewer *>(window->widget())->graphWindow;
584void CMainWindow::activateChild(QWidget *window) {
587 mdiArea->setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window));
static void out(agerrlevel_t level, const char *fmt, va_list args)
Report messages using a user-supplied or default write function.
int runSettings(MdiChild *m)
int showSettings(MdiChild *m)
void closeEvent(QCloseEvent *event)
void addFile(const QString &fileName)
CMainWindow(const QStringList &files)
QString userFriendlyCurrentFile()
bool loadFile(const QString &fileName)
int errorPipe(char *errMsg)
agusererrf agseterrf(agusererrf newf)
char ** gvPluginList(GVC_t *gvc, const char *kind, int *sz)
char * gvcVersion(GVC_t *gvc)
char * fileName(ingraph_state *sp)
Return name of current file being processed.
int errorPipe(char *errMsg)
static int LoadPlugins(QComboBox &cb, GVC_t *gvc, const char *kind, const QStringList &more, std::string_view prefer)
static const QStringList xtra
static void freeList(char **lp, int count)