9 #include "QHistogram.h"
10 #include "Histogram.h"
11 #include "IException.h"
12 #include <QFileDialog>
13 #include <QPrintDialog>
16 #include <QMessageBox>
18 #include <QVBoxLayout>
20 #include <qwt_plot_curve.h>
21 #include <qwt_plot_zoomer.h>
34 p_zoomer =
new QwtPlotZoomer(this->canvas());
35 setTitle(
"Histogram Plot");
37 QwtText *leftLabel =
new QwtText(
"Frequency", QwtText::PlainText);
38 leftLabel->setColor(Qt::red);
39 QFont font = leftLabel->font();
40 font.setPointSize(13);
42 leftLabel->setFont(font);
43 setAxisTitle(QwtPlot::yLeft, *leftLabel);
45 QwtText *rtLabel =
new QwtText(
"Percentage");
46 rtLabel->setColor(Qt::blue);
47 rtLabel->setFont(font);
48 setAxisTitle(QwtPlot::yRight, *rtLabel);
50 setAxisTitle(QwtPlot::xBottom,
"Pixel Value (DN)");
52 setAxisScale(QwtPlot::yRight, 0, 100);
53 enableAxis(QwtPlot::yRight,
true);
54 setCanvasBackground(Qt::white);
74 for(
int i = 0; i < hist.
Bins(); i++) {
80 cdfData.append(QPointF(hist.
BinMiddle(i), cumpct));
83 QPen *pen =
new QPen(Qt::red);
85 p_histCurve->setData(
new QwtPointSeriesData(histData));
90 pen->setColor(Qt::blue);
91 p_cdfCurve->setData(
new QwtPointSeriesData(cdfData));
106 if(
p_zoomer->trackerMode() == QwtPicker::ActiveOnly) {
107 p_zoomer->setTrackerMode(QwtPicker::AlwaysOn);
110 p_zoomer->setTrackerMode(QwtPicker::ActiveOnly);
131 static QPrinter *printer = NULL;
132 if(printer == NULL) printer =
new QPrinter;
133 printer->setPageSize(QPrinter::Letter);
134 printer->setColorMode(QPrinter::Color);
136 QPrintDialog printDialog(printer, (
QWidget *)parent());
137 if(printDialog.exec() == QDialog::Accepted) {
139 QPixmap pixmap = this->grab();
140 QImage img = pixmap.toImage();
143 QPainter painter(printer);
144 QRect rect = painter.viewport();
145 QSize size = img.size();
146 size.scale(rect.size(), Qt::KeepAspectRatio);
147 painter.setViewport(rect.x(), rect.y(),
148 size.width(), size.height());
149 painter.setWindow(img.rect());
150 painter.drawImage(0, 0, img);
162 QFileDialog::getSaveFileName((
QWidget *)parent(),
163 "Choose output file",
165 QString(
"Images (*.png *.jpg *.tif)"));
166 if(output.isEmpty())
return;
168 QString format = QFileInfo(output).suffix();
169 QPixmap pixmap = this->grab();
170 std::string formatString = format.toStdString();
171 if(!pixmap.save(output, formatString.c_str())) {
172 QMessageBox::information((
QWidget *)parent(),
"Error",
"Unable to save" + output);
183 QPen *pen =
new QPen(Qt::white);
184 if(canvasBackground() == Qt::white) {
185 setCanvasBackground(Qt::black);
190 setCanvasBackground(Qt::white);
191 pen->setColor(Qt::black);
205 d->setWindowTitle(
"Basic Help");
207 QLabel *zoomLabel =
new QLabel(
"Zoom Options:");
209 QLabel(
" <b>Left click</b> on the mouse, drag, and release to select an area to zoom in on");
210 QLabel *zoomOut =
new
211 QLabel(
" <b>Middle click</b> on the mouse to zoom out one level");
212 QLabel *zoomReset =
new
213 QLabel(
" <b>Right click</b> on the mouse to clear the zoom and return to the original plot");
215 QVBoxLayout *layout =
new QVBoxLayout();
216 layout->addWidget(zoomLabel);
217 layout->addWidget(zoomIn);
218 layout->addWidget(zoomOut);
219 layout->addWidget(zoomReset);
221 d->setLayout(layout);