00001
00022 #include "DGVMain.h"
00023
00024 #include <QFileDialog>
00025
00026 DGVMain::DGVMain(QWidget *parent) : QMainWindow(parent)
00027 {
00029 createMenu();
00030
00032 workspace = new QWorkspace(this);
00033 QMainWindow::setCentralWidget(workspace);
00034 windowMapper = new QSignalMapper(this);
00035
00037 createConnections();
00038 }
00039
00040 DGVMain::~DGVMain()
00041 {
00042
00043 }
00044
00045 void DGVMain::addImage(DGVImage *img)
00046 {
00047 workspace->addWindow(img);
00048 connect(img, SIGNAL(tableAvailable(DGVTable *)), this, SLOT(displayTable(DGVTable *)));
00049 }
00050
00051 void DGVMain::addTable(DGVTable *tbl)
00052 {
00053 workspace->addWindow(tbl);
00054 connect(tbl, SIGNAL(plotAvailable(DGVPlot *)), this, SLOT(displayPlot(DGVPlot *)));
00055 }
00056
00057 void DGVMain::addPlot(DGVPlot *plot)
00058 {
00059 workspace->addWindow(plot);
00060
00061 }
00062
00063
00064 void DGVMain::displayImage(DGVImage *img)
00065 {
00067 img->adjustSize();
00068 addImage(img);
00069 img->show();
00070 }
00071
00072 void DGVMain::displayTable(DGVTable *newTable)
00073 {
00075 newTable->resizeColumnsToContents();
00076 newTable->adjustSize();
00077 addTable(newTable);
00078 newTable->show();
00079 }
00080
00081 void DGVMain::displayPlot(DGVPlot *newPlot)
00082 {
00084 newPlot->adjustSize();
00085 addPlot(newPlot);
00086 newPlot->show();
00087 }
00088
00089 void DGVMain::open()
00090 {
00091 QFileDialog *fileOpener = new QFileDialog(this);
00092 QPixmap *pixmap = new QPixmap;
00093
00094 QString filename = fileOpener->getOpenFileName(this,
00095 tr("Select File to Open"),
00096 ".",
00097 tr("Images (*.png *.ppm *.pgm *.pbm *pnm *.tif *tiff *.jpeg *.jpg *.bmp)\nData Files (*.csv)"));
00098
00099 if (!filename.isEmpty())
00100 {
00101 if(filename.contains(".png", Qt::CaseInsensitive) || filename.contains(".ppm", Qt::CaseInsensitive)
00102 || filename.contains(".pgm", Qt::CaseInsensitive) || filename.contains(".jpeg", Qt::CaseInsensitive)
00103 || filename.contains(".jpg", Qt::CaseInsensitive) || filename.contains(".bmp", Qt::CaseInsensitive))
00104 {
00105 DGVImage *image = new DGVImage(this);
00106
00107 pixmap->load(filename);
00108
00110 image->setWindowTitle(filename);
00111 image->setPixmap(*pixmap);
00112 displayImage(image);
00113 }
00114 else if(filename.contains(".csv", Qt::CaseInsensitive))
00115 {
00116 DGVTable *table = new DGVTable(this);
00117
00118 if(table->loadCSV(filename))
00119 {
00120 table->setWindowTitle(filename);
00121 displayTable(table);
00122 }
00123 else
00124 {
00125 QMessageBox::warning(this, "DGV Error",
00126 "Unable to load data file.\n"
00127 "Check the data Delimiters and Try opening the file again.");
00128 }
00129 }
00130 }
00131 }
00132
00133 void DGVMain::save()
00134 {
00135 }
00136
00137 void DGVMain::newTable()
00138 {
00139 bool ok;
00140 int rows = QInputDialog::getInteger(this, tr("Enter the Number of Rows of the table."),
00141 tr("New Rows:"), 23, 0, INT_MAX, 1, &ok);
00142 int cols = QInputDialog::getInteger(this, tr("Enter the Number of Columns of the table."),
00143 tr("New Columns:"), 23, 0, INT_MAX, 1, &ok);
00144
00145 if(ok && rows > 0 && cols > 0)
00146 {
00147 DGVTable *table = new DGVTable(this);
00148
00149 table->setWindowTitle("New Table");
00150 table->setRowCount(rows);
00151 table->setColumnCount(cols);
00152 for(int j = 0; j < rows; j ++)
00153 for(int k = 0; k < cols; k ++)
00154 table->setItem(j,k,0);
00155 displayTable(table);
00156 }
00157 }
00158
00159 void DGVMain::newImage()
00160 {
00161 bool ok;
00162 int rows = QInputDialog::getInteger(this, tr("Enter the Number of Rows of the image."),
00163 tr("New Rows:"), 23, 0, INT_MAX, 1, &ok);
00164 int cols = QInputDialog::getInteger(this, tr("Enter the Number of Columns of the image."),
00165 tr("New Columns:"), 23, 0, INT_MAX, 1, &ok);
00166
00167 if(ok && rows > 0 && cols > 0)
00168 {
00169 DGVImage *image = new DGVImage(this);
00170 Array<imageType,2> newImageData(rows,cols);
00171
00172 image->setWindowTitle("New Image");
00173 newImageData = 0;
00174 image->setPixmap(newImageData);
00175 displayImage(image);
00176 }
00177 }
00178
00179 void DGVMain::cut()
00180 {
00181 }
00182
00183 void DGVMain::copy()
00184 {
00185 }
00186
00187 void DGVMain::paste()
00188 {
00189 }
00190
00191 void DGVMain::createMenu()
00192 {
00193 menuBar = new QMenuBar(this);
00194 menuFile = new QMenu(menuBar);
00195 menuNew = new QMenu(menuBar);
00196 menuWindows = new QMenu(menuBar);
00197 actionOpen = new QAction(this);
00198 actionSave = new QAction(this);
00199 actionExit = new QAction(this);
00200 actionNewTable = new QAction(this);
00201 actionNewImage = new QAction(this);
00202 actionCascade = new QAction(this);
00203 actionTile = new QAction(this);
00204
00206 menuBar->addAction(menuFile->menuAction());
00207 menuFile->addAction(menuNew->menuAction());
00208 menuFile->setTitle(QApplication::translate("MainWindow", "File", 0, QApplication::UnicodeUTF8));
00209 menuNew->setTitle(QApplication::translate("MainWindow", "New", 0, QApplication::UnicodeUTF8));
00210 actionOpen->setText(QApplication::translate("MainWindow", "Open...", 0, QApplication::UnicodeUTF8));
00211 actionSave->setText(QApplication::translate("MainWindow", "Save...", 0, QApplication::UnicodeUTF8));
00212 actionExit->setText(QApplication::translate("MainWindow", "Exit", 0, QApplication::UnicodeUTF8));
00214 menuFile->addAction(actionOpen);
00215 menuFile->addAction(actionSave);
00216 menuFile->addSeparator();
00217 menuFile->addAction(actionExit);
00219 actionNewTable->setText(QApplication::translate("MainWindow", "New Table", 0, QApplication::UnicodeUTF8));
00220 actionNewImage->setText(QApplication::translate("MainWindow", "New Image", 0, QApplication::UnicodeUTF8));
00221 menuNew->addAction(actionNewTable);
00222 menuNew->addAction(actionNewImage);
00224 menuBar->addAction(menuWindows->menuAction());
00225 menuWindows->setTitle(QApplication::translate("MainWindow", "Windows", 0, QApplication::UnicodeUTF8));
00226 actionCascade->setText(QApplication::translate("MainWindow", "Cascade", 0, QApplication::UnicodeUTF8));
00227 menuWindows->addAction(actionCascade);
00228 actionTile->setText(QApplication::translate("MainWindow", "Tile", 0, QApplication::UnicodeUTF8));
00229 menuWindows->addAction(actionTile);
00230
00231 setMenuBar(menuBar);
00232 }
00233
00234 void DGVMain::createConnections()
00235 {
00236 QObject::connect(actionOpen, SIGNAL(activated()), this, SLOT(open()));
00237 QObject::connect(actionSave, SIGNAL(activated()), this, SLOT(save()));
00238 QObject::connect(actionExit, SIGNAL(activated()), this, SLOT(close()));
00239 QObject::connect(actionNewTable, SIGNAL(activated()), this, SLOT(newTable()));
00240 QObject::connect(actionNewImage, SIGNAL(activated()), this, SLOT(newImage()));
00241 QObject::connect(actionCascade, SIGNAL(activated()), workspace, SLOT(cascade()));
00242 QObject::connect(actionTile, SIGNAL(activated()), workspace, SLOT(tile()));
00243 }