#include #include "GWt_dropZoneLigneFaiseau.h" #include "nomdElements.h" #include #include #include #include #include GWt_dropZoneLigneFaiseau::GWt_dropZoneLigneFaiseau(PspaApplication* ps,bool linkImageOk) : WContainerWidget(), pspa_(ps), insertMessage_(NULL), linkImage_(NULL), abstractElement_(NULL) { // decorationStyle().setBackgroundColor (WColor("yellow")); resize(5,5); cout<<"new GWt_dropZoneLigneFaiseau"<< endl; // connect mouse events mouseWentOver().connect(this, &GWt_dropZoneLigneFaiseau::mouseOver); mouseWentUp().connect(this, &GWt_dropZoneLigneFaiseau::mouseUp); mouseWentDown().connect(this, &GWt_dropZoneLigneFaiseau::mouseDown); mouseWentOut().connect(this, &GWt_dropZoneLigneFaiseau::mouseOut); mouseDragged().connect(this, &GWt_dropZoneLigneFaiseau::mouseIsDragged); insertMessage_ = new WText("Drag an element here"); addWidget(insertMessage_); if (linkImageOk) { linkImage_ = new WImage("icons/link.jpg"); linkImage_->setMargin(4, Top | Bottom); // add margin vertically addWidget(linkImage_); } insertMessage_->hide(); // accept drops int nElts= nomdElements::getNumberOfElements(); for(int k = 0; k < nElts; k++) { typedElement eType= (typedElement)k; acceptDrops(nomdElements::getImageFromType(eType)); } } GWt_dropZoneLigneFaiseau::~GWt_dropZoneLigneFaiseau() { } void GWt_dropZoneLigneFaiseau::mouseOver(const WMouseEvent& e) { // Add text if (insertMessage_) { if (!abstractElement_) { insertMessage_->show(); resize(insertMessage_->width(),insertMessage_->height()); } } if (linkImage_) { linkImage_->hide(); } decorationStyle().setBorder (WBorder (WBorder::Dashed, WBorder::Medium,WColor(blue))); pspa_->addConsoleMessage("mouse Over"); cout << " GWt_dropZoneLigneFaiseau::mouseOver" << endl; } void GWt_dropZoneLigneFaiseau::mouseOut(const WMouseEvent& e) { if (!abstractElement_) { if (linkImage_) { resize(linkImage_->width(),linkImage_->height()); } else { resize(10,10); } } if (insertMessage_) { insertMessage_->hide(); } if (linkImage_) { linkImage_->show(); } decorationStyle().setBorder (WBorder (WBorder::Dashed, WBorder::Medium,WColor(255,255,255,255))); pspa_->addConsoleMessage("GWt_dropZoneLigneFaiseau::mouseOut"); } void GWt_dropZoneLigneFaiseau::mouseIsDragged(const WMouseEvent& e) { pspa_->addConsoleMessage(" GWt_dropZoneLigneFaiseau::mouseDragged"); } void GWt_dropZoneLigneFaiseau::mouseUp(const WMouseEvent& e) { pspa_->addConsoleMessage("GWt_dropZoneLigneFaiseau::mouseOut up"); } void GWt_dropZoneLigneFaiseau::mouseDown(const WMouseEvent& e) { pspa_->addConsoleMessage("GWt_dropZoneLigneFaiseau::mouseDown up"); } void GWt_dropZoneLigneFaiseau::dropEvent(WDropEvent evt) { pspa_->addConsoleMessage(" GWt_dropZoneLigneFaiseau::dropEvent"); nomdElements e(evt.mimeType()); typedElement eType = e.getElementType(); // int cnts= pspa_->getDataManager()->beamLineSize(); // cout<<"GWt_LigneFaisceau::dropEvent() : "<addConsoleMessage(e.getElementName()); abstractElement* ptr = pspa_->getDataManager()->addElement(eType); ptr->setLabel(getElementNumberInBeamLine(e)); cout << " je vais ajouter l'element " << ptr->getName().getElementName() << " de type " << ptr->getName().getElementType() << endl; GWt_abstractElement* gw = GWt_abstractElement::ajoute(pspa_,ptr); if(gw == NULL) return; gw->updateLabelWidget(); // ////////////////////////////////////////////////////////////////// // // pourVoir // cout<<"container: "<getWidget()->id()<getWidget()->count(); k++) { // WWidget *w= gw->getWidget()->widget(k); // cout << w->id() << ", "; // } // cout << endl; // ////////////////////////////////////////////////////////////////// WSignalMapper *mapper= new WSignalMapper(this); mapper->mapped().connect(this,&GWt_dropZoneLigneFaiseau::onClick); mapper->mapConnect(gw->getButton()->doubleClicked(),gw); ////////////////////////////////////////////////////////////////// // add the dropped widget printf("add the dropped widget\n"); // add drop zone before and after if (static_cast (parent())) { WContainerWidget* wc = static_cast (parent()); cout<<"add the dropped parent %d"<< wc << " COUNT:"<< count () <<"<---------------"<< endl; // do not insert new element if some element is already present WBoxLayout* layout = ((WBoxLayout*)(wc->layout())); bool replaceElement = false; if (abstractElement_) { replaceElement = true; } // insert one before if (!replaceElement) { // if it the first element of the beam line if (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this))) == 0) { layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this))), new GWt_dropZoneLigneFaiseau(pspa_,false)); } else { layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this))), new GWt_dropZoneLigneFaiseau(pspa_,true)); } } // complete widget clear(); insertMessage_ = NULL; linkImage_ = NULL; abstractElement_ = gw->getWidget(); addWidget(abstractElement_); // change strech (useful if it was the last one) layout->setStretchFactor(this,0); // insert after // if it is the last, add a strech factor and no link image cout<<" nb elem:"<< layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1 << " COUNT:"<< wc->count () <<"<---------------"<< endl; if (!replaceElement) { if (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1 == wc->count()) { layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1, new GWt_dropZoneLigneFaiseau(pspa_,false),1); } else { layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1, new GWt_dropZoneLigneFaiseau(pspa_)); } } cout<<"add the dropped parent %d"<< wc << " COUNT:"<< wc->count () <<"<---------------"<< endl; } //gw->getWidget()->decorationStyle().setBackgroundColor (WColor("blue")); pspa_->updateSelections(); // ////////////////////////////////////////////////////////////////// // // pourVoir // cout << "number of items in the layout= " << hbox_->count() << ": "; // for(int k = 0; k < hbox_->count(); k++) // { // WLayoutItem *wi= hbox_->itemAt(k); // WWidget *w= wi->widget(); // cout << w->id() << ", "; // } // cout << endl; // ////////////////////////////////////////////////////////////////// // // pourVoir // int nElts= pspa_->getDataManager()->beamLineSize(); // cout << "GWt_LigneFaisceau:: nElts= " << nElts << endl; // unsigned int k; // for(k = 0; k < (unsigned)nElts; k++) { // abstractElement* ptr= pspa_->getDataManager()->getCollection()->getElementPointer(k); // string label= ptr->getLabel(); // cout << "GWt_LigneFaisceau:: " << label << " dans la liste" << endl; // } } void GWt_dropZoneLigneFaiseau::onClick(GWt_abstractElement* gw) { cout << "mouse key was double clicked on this widget " << gw->getWidget()->id()<< endl; messageDropZone_ = new GWt_dialog("Question","Are you sure you want to delete the selected item?",GWt_dialog::Warning,true,true); WSignalMapper *MyMap = new WSignalMapper(this); MyMap->mapped().connect(this, &GWt_dropZoneLigneFaiseau::removeDone); MyMap->mapConnect(messageDropZone_->finished(),gw); messageDropZone_->exec(); } void GWt_dropZoneLigneFaiseau::removeDone(GWt_abstractElement* gw) { if (messageDropZone_->result() == WDialog::Accepted) { cout <<"GWt_dropZoneLigneFaiseau:: removeDone "<< gw->getWidget()->id() << endl; clear(); string label= gw->getElement()->getLabel(); cout << "GWt_dropZoneLigneFaiseau:: " << label << " a été supprimé" << endl; pspa_->getDataManager()->getCollection()->eraseElement(label); pspa_->updateSelections(); } } void GWt_dropZoneLigneFaiseau::addElement(WContainerWidget* elem){ clear(); abstractElement_ = elem; addWidget(abstractElement_); insertMessage_ = NULL; linkImage_ = NULL; } std::string GWt_dropZoneLigneFaiseau::getElementNumberInBeamLine(nomdElements elem){ string str = ""; if (static_cast (parent())) { WContainerWidget* wc = static_cast (parent()); for (int a=0; acount(); a++) { if (static_cast (wc->widget (a))) { GWt_abstractElement* ab = static_cast (wc->widget (a)); /* printf("1--->%d\n",ab->getElement()); printf("2--->%d\n",ab->getElement()->getLenghtOfElement()); printf("3--->%d\n",ab->getElement()->getName().getElementType()); printf("4--->%d\n",elem.getElementType()); if (static_cast (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) { pspa_->addConsoleMessage("type trouvé"); } else { pspa_->addConsoleMessage("type trouvé NOT "); } */ } } int n = 999999; std::stringstream stream; stream << n ; std::string number(stream.str()); if(n < 10) { str= elem.getElementLabel()+"0"+number; } else { str= elem.getElementLabel()+" "+number; } } return str; }