mainwidget.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Author:  Jaime Valls Miro <jaime.vallsmiro@eng.uts.edu.au>
00004 **          Hue Tuan Thi <huetuan.thi@uts.edu.au>, (C) 2006
00005 **
00006 ** This file is part of the S3D Viewer Project
00007 **
00008 ** This file may be used under the terms of the GNU General Public
00009 ** License version 2.0 as published by the Free Software Foundation
00010 ** and appearing in the file LICENSE.GPL included in the packaging of
00011 ** this file.  Please review the following information to ensure GNU
00012 ** General Public Licensing requirements will be met:
00013 ** http://www.trolltech.com/products/qt/opensource.html
00014 **
00015 ** If you are unsure which license is appropriate for your use, please
00016 ** review the following information:
00017 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00018 ** sales department at sales@trolltech.com.
00019 **
00020 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022 **
00023 ****************************************************************************/
00024 
00032 #include <QtGui>
00033 #include <QtOpenGL>
00034 #include <QPixmap>
00035 #include "mainwidget.h"
00036 
00044 MainWidget::MainWidget()
00045 {
00046     // set window title
00047     setWindowTitle(tr("S3D Viewer"));
00048 
00049     // window size should be independent on screen resolution
00050     QDesktopWidget *d = QApplication::desktop();
00051     int w = d->width();     // returns desktop width
00052     int h = d->height();    // returns desktop height
00053     setGeometry ( w/6 , h/8 , w*2/3 , h*3/4 );
00054 
00055     // initialization for all the windows and widgets within
00056     refWindow = new QMainWindow(this);
00057     refImgWidget = new RefImgWidget(refWindow);
00058     point3dWidget = new Point3dWidget(this);
00059     setWindow = new SettingWindow(this);
00060     setWindow->setPointWidget(point3dWidget);
00061     fileReader = new FileReader();
00062     setCentralWidget(point3dWidget);
00063     refWindow->setCentralWidget(refImgWidget);
00064     statusBar()->showMessage(tr("S3d Viewer Initialized"));
00065     refImgWidget->setPointWidget(point3dWidget);
00066 
00067     // set up menu bar for our main window
00068     setupMenuBar();
00069 
00070     // for Fedora and Debian, we need to uncomment these following lines of code
00071     // refWindow->resize(1024, 1024); // required for Fedora and Debian
00072     // refWindow->setVisible(true); // required for Debian
00073 }
00074 
00078 MainWidget::~MainWidget()
00079 {
00080 }
00081 
00086 void MainWidget::setupMenuBar()
00087 {
00088     QMenu *menu = menuBar()->addMenu(tr("&File"));
00089     QAction *openAction = new QAction(tr("&Open File"), this);
00090     openAction->setShortcut(tr("Ctrl+O"));
00091     connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
00092 
00093     QAction *saveAction = new QAction(tr("&Save Bitmap"), this);
00094     saveAction->setShortcut(tr("Ctrl+S"));
00095     connect(saveAction, SIGNAL(triggered()), this, SLOT(saveBMP()));
00096 
00097     QAction *quitAction = new QAction(tr("&Quit"), this);
00098     quitAction->setShortcut(tr("Ctrl+Q"));
00099     connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
00100 
00101     menu->addAction(openAction);
00102     menu->addAction(saveAction);
00103     menu->addSeparator();
00104     menu->addAction(quitAction);
00105 
00106     menu = menuBar()->addMenu(tr("&View"));
00107 
00108     toggleImg = new QAction(tr("&Reference Image"), this);
00109     connect(toggleImg, SIGNAL(triggered()), this, SLOT(changeToggle()));
00110 
00111     showScene = new QAction(tr("Scene &Information"), this);
00112     connect(showScene, SIGNAL(triggered()), this, SLOT(sceneInfo()));
00113 
00114     showSetting = new QAction(tr("S&ettings"), this);
00115     showSetting->setShortcut(tr("Ctrl+E"));
00116     connect(showSetting, SIGNAL(triggered()), this, SLOT(showSettings()));
00117 
00118     menu->addAction(toggleImg);
00119     menu->addAction(showScene);
00120     menu->addAction(showSetting);
00121 
00122     toggleImg->setEnabled(false);
00123     showScene->setEnabled(false);
00124 
00125     menu = menuBar()->addMenu(tr("&About"));
00126 
00127     QAction *helpAction = new QAction(tr("&Help"), this);
00128     helpAction->setShortcut(tr("Ctrl+H"));
00129     connect(helpAction, SIGNAL(triggered()), this, SLOT(help()));
00130 
00131     QAction *aboutS3dAction = new QAction(tr("&About S3d Viewer"), this);
00132     aboutS3dAction->setShortcut(tr("Ctrl+A"));
00133     connect(aboutS3dAction, SIGNAL(triggered()), this, SLOT(aboutS3d()));
00134 
00135     QAction *aboutQtAction = new QAction(tr("About Q&T"), this);
00136     aboutQtAction->setShortcut(tr("Ctrl+T"));
00137     connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00138 
00139     menu->addAction(helpAction);
00140     menu->addAction(aboutS3dAction);
00141     menu->addAction(aboutQtAction);
00142 }
00143 
00148 void MainWidget::help(){
00149     QString helpText =
00150             tr("Open new S3d files by clicking on File->Open\n"
00151             "Save Bitmap of current S3d model by clicking on File->Save BMP\n"
00152             "Quit Program using File->Quit menu or click X on the top right\n\n"
00153             "Once S3d file is loaded, you can\n"
00154             "\tView->Reference Image to vew reference image of s3d file\n"
00155             "\tView->Scene Information to view information about s3d file\n"
00156             "\tView->Settings to edit settings\n\n"
00157             "Some useful tips in using this program\n"
00158             "\tUsing mouse to rotate model (press and drag)\n"
00159             "\tUsing mousewheel to zoom in and out\n"
00160             "\tUsing mousewheel to zoom in and out\n"
00161             "\tUsing Up and Down arrow to change zoom factor (like mousewheel)\n"
00162             "\tUsing Right and Left arrow to change Point Size (Cube option in Setting enabled)\n"
00163             "\tUsing shortcuts for quick command\n"
00164             "");
00165 
00166     QMessageBox::about( this, tr("Help"), helpText);
00167 }
00168 
00173 void MainWidget::aboutS3d(){
00174     QString aboutText =
00175             tr("S3dViewer for Unix-based Systems v1.0\n\n"
00176             "Authors: "
00177             "\tHue Tuan Thi\n"
00178             "\tJaime Valls Miro\n\n"
00179             "Centre of Autonomous System (CAS)\n"
00180             "University of Technoloty, Sydney (UTS)\n\n"
00181             "This program is used to view S3d files\n"
00182             "You can find out more about S3d files and a Windows version of this program at\n"
00183             "http://www.dccia.ua.es/~jmsaez/3D_Robot_Vision_Database\n"
00184             "");
00185 
00186     QMessageBox::about( this, tr("About S3dViewer"), aboutText);
00187 }
00188 
00194 void MainWidget::setVisible(QWidget *widget){
00195     if( widget->isVisible())
00196         widget->setVisible(false);
00197     else
00198         widget->setVisible(true);
00199 }
00200 
00205 void MainWidget::showSettings(){
00206     setVisible(setWindow);
00207 }
00208 
00213 void MainWidget::changeToggle(){
00214     setVisible(refWindow);
00215 }
00216 
00221 void MainWidget::sceneInfo(){
00222     QMessageBox::about( this, "Scene Information", sceneInformation);
00223 }
00224 
00229 void MainWidget::openFile(){
00230     fileName = QFileDialog::getOpenFileName(this, tr("Open S3D file ..."),
00231                                 "", tr("All Files (*);;S3D Files (*.s3d)"));
00232     if (!fileName.isEmpty()){
00233         fileReader->readFile(fileName);
00234         refImgWidget->updateFile(fileReader);
00235         point3dWidget->updateFile(fileReader);
00236 
00237         sceneInformation = QString("File name: %1 \nInformation: %2 \nColor format: %3 \nImage resolution: %4 x %5 pixels  \nNumber of 3D points: %6")
00238                             .arg(fileName).arg(fileReader->getInfo()).arg(fileReader->getColorText())
00239                             .arg(fileReader->getNRow()).arg(fileReader->getNCol()).arg(fileReader->getNp());
00240 
00241         refWindow->resize(fileReader->getNCol(), fileReader->getNRow()+20);
00242 
00243         if(fileReader->getEncoding() == 0)
00244             toggleImg->setEnabled(true);
00245         showScene->setEnabled(true);
00246     }
00247 }
00248 
00253 void MainWidget::saveBMP(){
00254     QSize size = getSize();
00255     if (size.isValid()) {
00256         QPixmap pixmap = point3dWidget->renderPixmap(size.width(), size.height());
00257 
00258         fileName = QFileDialog::getSaveFileName(this,
00259                         tr("Save BMP file"), "S3DBMP",
00260                         tr("All Files (*);;BMP Files (*.bmp)"));
00261 
00262         pixmap.save(fileName, "BMP");
00263         qDebug("Saved");
00264     }
00265 }
00266 
00271 QSize MainWidget::getSize()
00272 {
00273     bool ok;
00274     QString text = QInputDialog::getText(this, tr("S3dViewer"),
00275                     tr("Enter pixmap size:"), QLineEdit::Normal,
00276                     tr("%1 x %2").arg(point3dWidget->width()).arg(point3dWidget->height()), &ok);
00277     if (!ok)
00278         return QSize();
00279 
00280     QRegExp regExp(tr("([0-9]+) *x *([0-9]+)"));
00281     if (regExp.exactMatch(text)) {
00282         int width = regExp.cap(1).toInt();
00283         int height = regExp.cap(2).toInt();
00284         if (width > 0 && width < 2048 && height > 0 && height < 2048)
00285             return QSize(width, height);
00286     }
00287 
00288     return point3dWidget->size();
00289 }
00290 
00295 void MainWidget::closeEvent(QCloseEvent *ce){
00296     refWindow->close();
00297     setWindow->close();
00298 }

Generated on Mon Aug 14 10:44:19 2006 for S3DViewer by  doxygen 1.4.4