ImageDisplayLayout.qt.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <QtGui/QtGui>
00038 #include "Qt4/ImageDisplayLayout.qt.H"
00039 #include "Qt4/ImageView.qt.H"
00040
00041 using namespace std;
00042
00043
00044 ImageDisplayLayout::ImageDisplayLayout(QWidget *parent, const std::string& layout) :
00045 QWidget(parent)
00046 {
00047
00048 string layoutString;
00049 const string delimiter(" \t\r\n");
00050 for (string::const_iterator itr = layout.begin(); itr != layout.end(); ++itr)
00051 {
00052 if (delimiter.find(*itr) == string::npos)
00053 layoutString += *itr;
00054 }
00055 QGridLayout *grid = CreateLayout(layoutString.begin(), layoutString.end());
00056 if (grid != NULL)
00057 {
00058 setLayout(grid);
00059 }
00060 }
00061
00062
00063 ImageDisplayLayout::~ImageDisplayLayout()
00064 {
00065 }
00066
00067
00068 QGridLayout *ImageDisplayLayout::CreateLayout(string::const_iterator begin, string::const_iterator end)
00069 {
00070 if (begin == end) return NULL;
00071
00072 int row = 0;
00073 int col = 0;
00074 QGridLayout *grid = new QGridLayout;
00075
00076 for (string::const_iterator itr = begin; itr != end;)
00077 {
00078 if (*itr == '(')
00079 {
00080 int parenthese_count = 1;
00081 for (string::const_iterator itr2 = itr + 1; itr2 != end; ++itr2)
00082 {
00083 if (*itr2 == '(')
00084 {
00085 parenthese_count++;
00086 }
00087 else if (*itr2 == ')')
00088 {
00089 parenthese_count--;
00090 if (parenthese_count == 0)
00091 {
00092 QGridLayout *grid2 = CreateLayout(itr + 1, itr2);
00093 if (grid2 != NULL)
00094 {
00095 grid->addLayout(grid2, row, col);
00096 }
00097 itr = itr2 + 1;
00098 break;
00099 }
00100 }
00101 }
00102 if (parenthese_count != 0) LFATAL("Unbalanced parentheses detected in layout string");
00103 if (itr == end) break;
00104 }
00105 if (*itr == ',')
00106 {
00107 col++;
00108 ++itr;
00109 }
00110 else if(*itr == ';')
00111 {
00112 col = 0;
00113 row++;
00114 ++itr;
00115 }
00116 else
00117 {
00118 string::const_iterator itr2 = itr;
00119 string name;
00120 for (; itr2 != end && *itr2 != ',' && *itr2 != ';' && *itr2 != '(' && *itr2 != ')'; ++itr2)
00121 {
00122 name += *itr2;
00123 }
00124 ImageView *view = new ImageView(0, name.c_str());
00125 grid->addWidget(view, row, col);
00126 itsViews.insert(pair<string,ImageView*>(name, view));
00127 itr = itr2;
00128 }
00129 }
00130 return grid;
00131 }
00132
00133
00134 ImageView* ImageDisplayLayout::view(const char* name)
00135 {
00136 map<std::string, ImageView*>::iterator item = itsViews.find(string(name));
00137 return (item == itsViews.end()) ? NULL : item->second;
00138 }
00139
00140
00141 void ImageDisplayLayout::setImage(const char* name, Image< PixRGB<byte> > img)
00142 {
00143 ImageView* v = view(name);
00144 if (v == NULL) LFATAL("Accessing a NULL or not existing view '%s'", name);
00145 v->setImage(img);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154