forked from ruben2020/codequery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphdialog.cpp
142 lines (124 loc) · 3.97 KB
/
graphdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* CodeQuery
* Copyright (C) 2013 ruben2020 https://github.com/ruben2020/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ui_graphDialog.h"
#include "graphdialog.h"
#include "showgraph.h"
cqDialogGraph::cqDialogGraph(QWidget *parent)
:QDialog(parent)
,dialog_ui(new Ui::DialogGraph)
,m_scaleFactor(5.0)
{
dialog_ui->setupUi(this);
connect(dialog_ui->pushButtonClose, SIGNAL(clicked()),
this, SLOT(accept()));
connect(dialog_ui->pushButtonZoomOut, SIGNAL(clicked()),
this, SLOT(zoomout()));
connect(dialog_ui->pushButtonZoomIn, SIGNAL(clicked()),
this, SLOT(zoomin()));
/*connect(dialog_ui->checkBoxAutoResize, SIGNAL(stateChanged(int)),
this, SLOT(autoResizeChanged(int)));*/
connect(dialog_ui->pushButtonSave, SIGNAL(clicked()),
this, SLOT(savetoimagefile()));
connect(dialog_ui->pushButtonSaveDot, SIGNAL(clicked()),
this, SLOT(savetodotfile()));
}
cqDialogGraph::~cqDialogGraph()
{
disconnect();
delete dialog_ui;
}
void cqDialogGraph::setupGraphFromXML(QString grpxml, QString grpdot, QString desc)
{
showgraph sg;
m_dot = grpdot;
m_img = sg.convertToImage(grpxml);
dialog_ui->labelGraph->setPixmap(QPixmap::fromImage(m_img));
dialog_ui->labelGraph->setMask(dialog_ui->labelGraph->pixmap()->mask());
dialog_ui->labelDesc->setText(desc);
show();
adjustScrollBar(dialog_ui->scrollArea->horizontalScrollBar(), m_scaleFactor/5);
adjustScrollBar(dialog_ui->scrollArea->verticalScrollBar(), m_scaleFactor/5);
}
void cqDialogGraph::zoomout()
{
scaleImage(-1);
}
void cqDialogGraph::zoomin()
{
scaleImage(1);
}
void cqDialogGraph::savetoimagefile()
{
QString filetype = tr("Images");
filetype += " (*.png *.jpg *.bmp *.tiff)";
QString fileName =
QFileDialog::getSaveFileName( this, tr("Export Image"),
QDir::currentPath(),
filetype);
if (fileName.isEmpty()) return;
QMessageBox msgBox(this);
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Ok);
QImageWriter writer( fileName);
if ((writer.canWrite() && writer.write(m_img)) == false)
{
msgBox.setText(tr("File could not be saved!"));
msgBox.exec();
}
}
void cqDialogGraph::savetodotfile()
{
QString fileName =
QFileDialog::getSaveFileName( this, tr("Export DOT file"),
QDir::currentPath(),
"Graphviz DOT (*.dot)");
if (fileName.isEmpty()) return;
QFile outfile(fileName);
QMessageBox msgBox(this);
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Ok);
if (outfile.open(QIODevice::WriteOnly | QIODevice::Text) == false)
{
msgBox.setText(tr("File could not be saved!"));
msgBox.exec();
return;
}
QTextStream out(&outfile);
out << m_dot;
outfile.close();
}
void cqDialogGraph::scaleImage(double factor)
{
QPixmap p = QPixmap::fromImage(m_img);
m_scaleFactor += factor;
m_scaleFactor = (m_scaleFactor < 1.0) ? 1.0 : m_scaleFactor;
dialog_ui->labelGraph->setPixmap(p.scaled((m_scaleFactor/5) * p.size(), Qt::KeepAspectRatio));
adjustScrollBar(dialog_ui->scrollArea->horizontalScrollBar(), m_scaleFactor/5);
adjustScrollBar(dialog_ui->scrollArea->verticalScrollBar(), m_scaleFactor/5);
}
void cqDialogGraph::adjustScrollBar(QScrollBar *scrollBar, double factor)
{
int minim = scrollBar->minimum();
scrollBar->setValue((scrollBar->maximum() - minim)/2 + minim);
}
/*
void cqDialogGraph::autoResizeChanged(int resizestate)
{
dialog_ui->scrollArea->setWidgetResizable(resizestate == Qt::Checked);
}*/