@@ -5,6 +5,7 @@ NodeCore::NodeCore()
55 setAcceptedMouseButtons (Qt::AllButtons);
66}
77
8+
89void NodeCore::setBackgroundColor (const QColor color)
910{
1011 if (color==m_backgroundColor)
@@ -128,6 +129,9 @@ void NodeCore::paint(QPainter *painter)
128129 DrawBody (painter);
129130 DrawTitle (painter);
130131 DrawPorts (painter);
132+ DrawLabels (painter);
133+ DrawCheckBoxes (painter);
134+ DrawNumberBoxes (painter);
131135}
132136void NodeCore::DrawBody (QPainter *painter)
133137{
@@ -173,6 +177,61 @@ void NodeCore::DrawPorts(QPainter *e)
173177 e->drawEllipse (outputPort[i].Position ,r,r);
174178 }
175179}
180+ void NodeCore::DrawLabels (QPainter *e)
181+ {
182+ for (int i=0 ;i<labelList.length ();i++)
183+ {
184+ e->setPen (labelList[i].Color );
185+ e->setFont (labelList[i].Font );
186+ e->drawText (labelList[i].Pos ,labelList[i].Text );
187+ }
188+ }
189+ void NodeCore::DrawCheckBoxes (QPainter *e)
190+ {
191+ for (int i=0 ;i<checkBoxList.length ();i++)
192+ {
193+ CheckBox *c=&checkBoxList[i];
194+ e->setPen (c->BorderColor );
195+ e->drawRect (c->Pos .x (),c->Pos .y (),c->Width ,c->Height );
196+ if (c->State ==CheckBoxState::Off)
197+ {
198+ e->fillRect (c->Pos .x (),c->Pos .y (),c->Width ,c->Height ,c->BackColor );
199+ }
200+ else
201+ {
202+ e->fillRect (c->Pos .x (),c->Pos .y (),c->Width ,c->Height ,c->FillColor );
203+ e->setPen (QPen (c->TickColor ,2 ));
204+ QPoint p1=c->Pos +QPoint (c->Width /6 ,1 *c->Height /2 );
205+ QPoint p2=c->Pos +QPoint (2 *c->Width /5 ,7 *c->Height /9 );
206+ QPoint p3=c->Pos +QPoint (4 *c->Width /5 ,1 *c->Height /5 );
207+
208+ e->drawLine (p1,p2);
209+ e->drawLine (p2,p3);
210+ }
211+ }
212+ }
213+
214+ void NodeCore::DrawNumberBoxes (QPainter *e)
215+ {
216+ for (int i=0 ;i<numberBoxList.length ();i++)
217+ {
218+ NumberBox *n=&numberBoxList[i];
219+ e->setPen (n->BorderColor );
220+ e->drawRect (n->Pos .x (),n->Pos .y (),n->Width ,n->Height );
221+ QColor bcol=currentNumberBox==nullptr ?n->BackgroundColor :n->HighlightColor ;
222+ e->fillRect (n->Pos .x (),n->Pos .y (),n->Width ,n->Height ,bcol);
223+ QFontMetrics f (n->Font );
224+ int x=f.width (n->Text );
225+ int y=f.height ();
226+ e->setPen (n->ForeGroundColor );
227+ e->setFont (n->Font );
228+ QString text=n->Text ;
229+ if (currentNumberBox!=nullptr )
230+ text.insert (n->CursorPos ,' |' );
231+ QPoint p=n->Pos +QPoint (5 ,2 *y/3 );
232+ e->drawText (p,text);
233+ }
234+ }
176235
177236bool NodeCore::IsMouseOnHeader (QPoint p)
178237{
@@ -196,13 +255,14 @@ void NodeCore::mousePressEvent(QMouseEvent *e)
196255 else
197256 {
198257 PortClickHelper (e->pos ());
258+ CheckBoxClickHelper (e->pos ());
259+ NumberBoxClickHelper (e->pos ());
199260 }
200261}
201262
202263
203264void NodeCore::mouseMoveEvent (QMouseEvent *e)
204265{
205- DrawRopes ();
206266 if (mouseClickedOnHeader)
207267 {
208268 QPoint curr=QPoint (static_cast <int >(position ().x ()),static_cast <int >(position ().y ()));
@@ -219,6 +279,14 @@ void NodeCore::mouseReleaseEvent(QMouseEvent *e)
219279 ReleasePortTargeter (e->pos ());
220280
221281}
282+ void NodeCore::focusOutEvent (QFocusEvent *e)
283+ {
284+ if (e->lostFocus ())
285+ {
286+ currentNumberBox=nullptr ;
287+ update ();
288+ }
289+ }
222290
223291Port *NodeCore::GetClickedPort (QPoint e)
224292{
@@ -271,6 +339,13 @@ void NodeCore::DrawRopes()
271339 p1.Position += QPoint (0 , 30 );
272340 outputPort.push_back (P);
273341 p1.PortColor = QColor (Qt::magenta);
342+ Label l;
343+ l.Text =" X" ;
344+ l.Pos =P.Position -QPoint (40 ,-5 );
345+ labelList.push_back (l);
346+ NumberBox n;
347+ n.Pos =QPoint (20 ,65 );
348+ numberBoxList.append (n);
274349 outputPort.push_back (p1);
275350
276351 }
@@ -309,6 +384,38 @@ void NodeCore::PortClickHelper(QPoint e)
309384 currentPort=p;
310385 }
311386}
387+
388+ void NodeCore::CheckBoxClickHelper (QPoint e)
389+ {
390+ CheckBox* c=GetClickedCheckBox (e);
391+ if (c!=nullptr )
392+ {
393+ if (c->State ==CheckBoxState::On)
394+ {
395+ c->State =CheckBoxState::Off;
396+ }
397+ else
398+ {
399+ c->State =CheckBoxState::On;
400+ }
401+ update ();
402+ }
403+ }
404+ void NodeCore::NumberBoxClickHelper (QPoint e)
405+ {
406+ NumberBox* c=GetClickedNumberBox (e);
407+ if (c!=nullptr )
408+ {
409+ currentNumberBox=c;
410+ }
411+ else
412+ {
413+ currentNumberBox=nullptr ;
414+
415+ }
416+ update ();
417+
418+ }
312419void NodeCore::PortLineMoveHelper (QPoint e)
313420{
314421 if (inputPortClicked||outPutPortClicked)
@@ -425,3 +532,78 @@ void NodeCore::ConnectionRemover()
425532 currentPort->InputPort ->Target =nullptr ;
426533 }
427534}
535+ CheckBox* NodeCore::GetClickedCheckBox (QPoint e)
536+ {
537+ CheckBox* p=nullptr ;
538+
539+ for (int i=0 ;i<checkBoxList.length ();i++)
540+ {
541+ if (abs (e.x ()-checkBoxList[i].Pos .x ())<=checkBoxList[i].Width )
542+ {
543+ if (abs (e.y ()-checkBoxList[i].Pos .y ())<=checkBoxList[i].Height )
544+ {
545+ p=&checkBoxList[i];
546+ }
547+ }
548+ }
549+ return p;
550+ }
551+
552+ NumberBox* NodeCore::GetClickedNumberBox (QPoint e)
553+ {
554+ NumberBox* p=nullptr ;
555+
556+ for (int i=0 ;i<numberBoxList.length ();i++)
557+ {
558+ if (abs (e.x ()-numberBoxList[i].Pos .x ())<=numberBoxList[i].Width )
559+ {
560+ if (abs (e.y ()-numberBoxList[i].Pos .y ())<=numberBoxList[i].Height )
561+ {
562+ p=&numberBoxList[i];
563+ }
564+ }
565+ }
566+ return p;
567+ }
568+
569+ void NodeCore::keyPressEvent (QKeyEvent *e)
570+ {
571+ if (currentNumberBox!=nullptr )
572+ {
573+ if (e->key ()==Qt::Key::Key_Backspace)
574+ {
575+ if (currentNumberBox->CursorPos >0 )
576+ {
577+ currentNumberBox->Text .remove (currentNumberBox->CursorPos -1 ,1 );
578+ currentNumberBox->CursorPos --;
579+ }
580+ }
581+ if (e->key ()==Qt::Key::Key_Delete)
582+ {
583+ // if(currentNumberBox->CursorPos<currentNumberBox->Text.length())
584+ {
585+ currentNumberBox->Text .remove (currentNumberBox->CursorPos ,1 );
586+ }
587+ }
588+ if (e->key ()==Qt::Key::Key_Left)
589+ {
590+ if (currentNumberBox->CursorPos >0 )
591+ {
592+ currentNumberBox->CursorPos --;
593+ }
594+ }
595+ if (e->key ()==Qt::Key::Key_Right)
596+ {
597+ if (currentNumberBox->CursorPos <currentNumberBox->Text .length ())
598+ {
599+ currentNumberBox->CursorPos ++;
600+ }
601+ }
602+ if ((e->key ()>=48 && e->key ()<=57 )|| e->key ()==46 )
603+ {
604+ currentNumberBox->Text .insert (currentNumberBox->CursorPos ,static_cast <QChar>(e->key ()));
605+ currentNumberBox->CursorPos ++;
606+ }
607+ update ();
608+ }
609+ }
0 commit comments