00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "PSQt/DragStore.h"
00011
00012 #include "PSQt/DragCircle.h"
00013 #include "PSQt/DragCenter.h"
00014
00015
00016 using namespace std;
00017
00018
00019
00020 namespace PSQt {
00021
00022
00023
00024 DragStore::DragStore(WdgImage* wimg)
00025 : m_wimg(wimg)
00026 , p_dragfig_sel(0)
00027 {
00028
00029
00030 QPointF center_raw(2000,2000);
00031 v_dragfigs.clear();
00032 v_dragfigs.push_back((DragFig){DragStore::Create(m_wimg, DRAGCENTER, ¢er_raw), DRAGCENTER, 0});
00033
00034 QPen pen_boarder(Qt::white, 1, Qt::DashLine);
00035 this -> addCircle(100, &pen_boarder);
00036 this -> addCircle(200, &pen_boarder);
00037 this -> addCircle(300, &pen_boarder);
00038 this -> addCircle(400, &pen_boarder);
00039 this -> addCircle(500, &pen_boarder);
00040 }
00041
00042
00043
00044 void
00045 DragStore::addCircle(const float& rad_raw, const QPen* pen)
00046 {
00047 QPointF pc = this -> getCenter();
00048 QPointF points_raw[2] = { pc,
00049 pc + QPointF(rad_raw,rad_raw) };
00050 v_dragfigs.push_back((DragFig){DragStore::Create(m_wimg, DRAGCIRCLE, &points_raw[0]), DRAGCIRCLE, 0});
00051
00052 if(pen) v_dragfigs.back().ptr_obj->setPenDraw(*pen);
00053
00054 }
00055
00056
00057
00058 void
00059 DragStore::drawFigs(const DRAGMODE& mode)
00060 {
00061 for(std::vector<DragFig>::iterator it=v_dragfigs.begin(); it!= v_dragfigs.end(); ++ it) {
00062
00063 if ((p_dragfig_sel && p_dragfig_sel->type == DRAGCENTER)
00064 || &(*it) == p_dragfig_sel) it -> ptr_obj -> draw(mode);
00065 else it -> ptr_obj -> draw();
00066 }
00067 }
00068
00069
00070
00071 bool
00072 DragStore::containFigs(const QPointF& p)
00073 {
00074 for(std::vector<DragFig>::iterator it=v_dragfigs.begin(); it!= v_dragfigs.end(); ++ it)
00075 if(it->ptr_obj -> contains(p)) {
00076 p_dragfig_sel = &(*it);
00077 return true;
00078 }
00079 return false;
00080 }
00081
00082
00083
00084 void
00085 DragStore::moveFigs(const QPointF& p)
00086 {
00087
00088 p_dragfig_sel -> ptr_obj -> move(p);
00089 }
00090
00091
00092
00093 void
00094 DragStore::moveFigsIsCompleted(const QPointF& p)
00095 {
00096
00097 p_dragfig_sel -> ptr_obj -> moveIsCompleted(p);
00098 }
00099
00100
00101
00102 void
00103 DragStore::deleteFig()
00104 {
00105
00106 if(v_dragfigs.size()<4) { MsgInLog(_name_(), WARNING, "Last two circles can't be removed" ); return; }
00107
00108 if(p_dragfig_sel->type == DRAGCENTER) { MsgInLog(_name_(), WARNING, "Center can't be removed" ); return; }
00109
00110 for(std::vector<DragFig>::iterator it=v_dragfigs.begin(); it!= v_dragfigs.end(); ++ it)
00111
00112 if( &(*it) == p_dragfig_sel) {
00113 v_dragfigs.erase(it);
00114 p_dragfig_sel = 0;
00115 return;
00116 }
00117 }
00118
00119
00120
00121 void
00122 DragStore::print()
00123 {
00124 stringstream ss; ss << strTimeStamp() << " DragStore::print():";
00125 std::cout << ss.str() << '\n';
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 const char*
00135 DragStore::cstrDragType(const DRAGTYPE& dfigtype)
00136 {
00137 if (dfigtype == DRAGCIRCLE) { return "CIRCLE"; }
00138 if (dfigtype == DRAGCENTER) { return "CENTER"; }
00139 if (dfigtype == DRAGLINE ) { return "LINE"; }
00140 return "N/A TYPE";
00141 }
00142
00143
00144
00145 PSQt::DragBase*
00146 DragStore::Create(WdgImage* wimg, const DRAGTYPE& dfigtype, const QPointF* points, const int& npoints)
00147 {
00148 stringstream ss; ss << "Create " << std::string(cstrDragType(dfigtype))
00149 << " with pars: npoints=" << npoints;
00150 for(int i=0; i<npoints; ++i) ss << ", (" << points[i].x() << ", " << points[i].y() << ")";
00151 MsgInLog(_name_(), INFO, ss.str());
00152
00153 if (dfigtype == DRAGCIRCLE) { return new PSQt::DragCircle(wimg, points); }
00154 if (dfigtype == DRAGCENTER) { return new PSQt::DragCenter(wimg, points); }
00155
00156
00157 stringstream ss2; ss2 << "Unknown draggable figure name " << std::string(cstrDragType(dfigtype)) << " - return 0-pointer...";
00158 MsgInLog(_name_(), WARNING, ss2.str() );
00159
00160 return 0;
00161 }
00162
00163
00164
00165 }
00166
00167
00168
00169