box.cpp

Go to the documentation of this file.
00001 #include <qfiledialog.h>
00002 #include "box.h"
00003 #include "image.h"
00004 #include "runtime.h"
00005 
00006 QString BoxValue::toString()
00007 {
00008   return QString("(")+
00009     tl.toString()+QString(", ")+
00010     tr.toString()+QString(", ")+
00011     br.toString()+QString(", ")+
00012     bl.toString()+QString(")");
00013 }
00014 
00015 bool BoxValue::equals_same_type(Value * other)
00016 {
00017   BoxValue *o = (BoxValue*)other;
00018   return tl.equals(o->tl) &&
00019     tr.equals(o->tr) &&
00020     bl.equals(o->bl) &&
00021     br.equals(o->br);
00022 }
00023 
00024 Value * Runtime::box(Value * image)
00025 {
00026   if (image==NULL)  return NULL;
00027   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00028   ImageValue * I = (ImageValue*)image;
00029   BoxPicker ip(I);
00030   if (ip.exec()==QDialog::Accepted)
00031     return ip.value();
00032   return NULL;
00033 }
00034 
00035 Value * Runtime::box(vector<Value*> v)
00036 {
00037   if (v.size()==1) return box(v[0]);
00038   return NULL;
00039 }
00040 
00041 void BoxPicker::nextPoint(PointValue p, bool final)
00042 {
00043   if (nr == 0)
00044     {
00045       box.tl = p;
00046       nr = 1;
00047     }
00048   else if (nr == 1)
00049     {
00050       if (final)
00051         {
00052           box.br = p;
00053           box.tr.x = box.br.x;
00054           box.tr.y = box.tl.y;
00055           box.bl.x = box.tl.x;
00056           box.bl.y = box.br.y;
00057           accept();
00058         }
00059       else
00060         {
00061           box.tr = p;
00062           nr = 2;
00063         }
00064     }
00065   else if (nr == 2)
00066     {
00067       box.br = p;
00068       nr = 3;
00069     }
00070   else if (nr == 3)
00071     {
00072       box.bl = p;
00073       accept();
00074     }
00075 }

Generated on Mon Jun 5 22:08:41 2006 for iis by  doxygen 1.4.6