00001
00007 #include "wframe.h"
00008
00009 #include <QtGui/qmenubar.h>
00010 #include <QtGui/qfiledialog.h>
00011 #include <QtGui/qtoolbar.h>
00012 #include <QtGui/qstatusbar.h>
00013 #include <QtGui/QHBoxLayout>
00014
00015 #include "palette.h"
00016 #include "visu2d.h"
00017 #include "image.h"
00018 #include "wstatistics.h"
00019
00020 #include <iostream>
00021
00027 WFrame::WFrame( QMainWindow* parent, const QString& appPath, Qt::WFlags fl )
00028 : QMainWindow(parent, fl)
00029 {
00030 m_applicationPath = appPath;
00031 setWindowTitle( "DrawQt : main window" );
00032
00033 QWidget *w = new QWidget;
00034 QHBoxLayout *hbox = new QHBoxLayout(w);
00035 m_palette = new Palette;
00036 hbox->addWidget(m_palette);
00037 m_visu2d = new Visu2D;
00038 hbox->addWidget(m_visu2d);
00039 m_wstats = new WStatistics;
00040 hbox->addWidget(m_wstats);
00041 hbox->setStretchFactor(m_palette, 0);
00042 hbox->setStretchFactor(m_visu2d, 1);
00043 hbox->setStretchFactor(m_wstats, 0);
00044
00045 setCentralWidget(w);
00046
00047 InitMenus();
00048 InitToolBar();
00049
00050 m_label = new QLabel("Info");
00051 m_label->setMinimumWidth(200);
00052 statusBar()->addWidget(m_label);
00053
00054 m_pImage = new Image;
00055
00056 connect(m_palette, SIGNAL(PaletteModified()), SLOT(UpdateColorMap()));
00057 connect(m_visu2d, SIGNAL(UpdateInfoBar(const QString&)),SLOT(UpdateStatusBar(const QString&)));
00058 connect(m_visu2d, SIGNAL(UpdateStats(Selection*)), this, SLOT(UpdateStats(Selection*)));
00059 connect(m_wstats, SIGNAL(SaveSelection()), m_visu2d, SLOT(SaveSelection()));
00060 connect(m_wstats, SIGNAL(ReadSelection()), m_visu2d, SLOT(ReadSelection()));
00061 }
00062
00066 WFrame::~WFrame()
00067 {
00068 delete m_pImage;
00069 }
00070
00074 void WFrame::InitMenus()
00075 {
00076 QMenu *fileMenu = new QMenu("File");
00077 fileMenu->addAction("Read image", this, SLOT(ReadImage()));
00078 fileMenu->addAction("&Quit", this, SLOT(close()));
00079 menuBar()->addMenu(fileMenu);
00080
00081 menuBar()->addMenu(m_palette->GetMenu());
00082 }
00083
00084
00085
00086
00087 void WFrame::InitToolBar()
00088 {
00089 QString strDirIcons = m_applicationPath+"/../Resources/data/icons";
00090 QDir dir(strDirIcons);
00091 if (!dir.exists()) {
00092 strDirIcons = "./data/icons";
00093 if (!QDir(strDirIcons).exists()) {
00094 strDirIcons = "../data/icons";
00095 }
00096 }
00097
00098
00099 QToolBar *toolBarShape = new QToolBar(this);
00100 addToolBar(Qt::TopToolBarArea, toolBarShape);
00101
00102
00103 m_actionRectangle = toolBarShape->addAction(QIcon(strDirIcons+"/Rect.bmp"), "Rectangular shape", this, SLOT(ClickRectangle()));
00104 m_actionRectangle->setShortcut(tr("Ctrl+R"));
00105 m_actionRectangle->setCheckable(TRUE);
00106
00107
00108 toolBarShape->addSeparator();
00109
00110
00111
00112 m_actionRectangle->setChecked(TRUE);
00113 m_actionCurrentShape = m_actionRectangle;
00114 m_visu2d->SetShapeType(RECTANGLE);
00115 }
00116
00117 bool WFrame::ReadImage()
00118 {
00119 QString fname = QFileDialog::getOpenFileName(this,
00120 "Select a file",
00121 ".",
00122 "Images (*.dat)");
00123
00124 if(!m_pImage->ReadFile(fname.toStdString())) {
00125 std::cout << "Error reading image : unknown format" << std::endl;
00126 return false;
00127 }
00128 m_palette->ChangeDataMinMax(m_pImage->GetMin(), m_pImage->GetMax());
00129 m_visu2d->UpdateDataAndPixmap(m_pImage, m_palette);
00130 return true;
00131 }
00132
00133 void WFrame::ClickRectangle()
00134 {
00135 SetType(m_actionRectangle, RECTANGLE);
00136 }
00137
00138 void WFrame::SetType(QAction* tb, SHAPE_TYPE type)
00139 {
00140 m_actionCurrentShape->setChecked(FALSE);
00141 m_actionCurrentShape = tb;
00142 m_actionCurrentShape->setChecked(TRUE);
00143 m_visu2d->SetShapeType(type);
00144 }
00145
00146 void WFrame::UpdateStatusBar(const QString& s)
00147 {
00148 m_label->setText(s);
00149 }
00150
00151 void WFrame::UpdateColorMap()
00152 {
00153 m_visu2d->UpdateDataAndPixmap(m_pImage, m_palette);
00154 }
00155
00156 void WFrame::UpdateStats(Selection* pSelection)
00157 {
00158 m_wstats->UpdateStats(pSelection, m_pImage);
00159 }