Skip to content

Commit 1f3ebe7

Browse files
committed
CoreUI Component Being Written
Few UI Component Being Written
1 parent 0b8d377 commit 1f3ebe7

8 files changed

Lines changed: 296 additions & 4 deletions

File tree

Operator.pro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
3535
HEADERS += \
3636
blackboard.h \
3737
nodecore.h \
38-
port.h
38+
port.h \
39+
labelcore.h \
40+
checkboxcore.h \
41+
numberboxcore.h \
42+
coreui.h

checkboxcore.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef CHECKBOXCORE_H
2+
#define CHECKBOXCORE_H
3+
#include<QColor>
4+
#include<QPoint>
5+
#include<QPainter>
6+
#include<QDebug>
7+
#include<coreui.h>
8+
9+
enum CheckBoxState
10+
{
11+
On,Off
12+
};
13+
14+
class CheckBox:public CoreUI
15+
{
16+
public:
17+
QPoint Pos;
18+
CheckBoxState State=CheckBoxState::Off;
19+
QColor BackColor=QColor(52,52,52);
20+
QColor FillColor=QColor(30,141,255);
21+
QColor TickColor=QColor(Qt::white);
22+
QColor BorderColor=QColor(Qt::black);
23+
int Width=20;
24+
int Height=20;
25+
};
26+
27+
#endif // CHECKBOXCORE_H

coreui.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef COREUI_H
2+
#define COREUI_H
3+
class CoreUI
4+
{
5+
6+
};
7+
8+
#endif // COREUI_H

labelcore.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef LABELCORE_H
2+
#define LABELCORE_H
3+
#include<QString>
4+
#include<QPoint>
5+
#include<QColor>
6+
#include<QFont>
7+
#include<coreui.h>
8+
class Label:public CoreUI
9+
{
10+
public:
11+
QString Text;
12+
QFont Font=QFont("Segoe UI",12,-1,true);
13+
QPoint Pos=QPoint(0,0);
14+
QColor Color=QColor(Qt::white);
15+
};
16+
17+
#endif // LABELCORE_H

main.qml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Window {
4040
panelGradColor: "purple"
4141
width: 200
4242
height: 200
43+
44+
4345
}
4446

4547

nodecore.cpp

Lines changed: 183 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ NodeCore::NodeCore()
55
setAcceptedMouseButtons(Qt::AllButtons);
66
}
77

8+
89
void 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
}
132136
void 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

177236
bool 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

203264
void 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

223291
Port *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+
}
312419
void 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+
}

nodecore.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#include<QPainter>
66
#include "port.h"
77
#include<QList>
8-
#include<QWidget>
98
#include"blackboard.h"
9+
#include<labelcore.h>
10+
#include<checkboxcore.h>
11+
#include<numberboxcore.h>
1012

1113
class NodeCore : public QQuickPaintedItem
1214
{
@@ -23,6 +25,7 @@ class NodeCore : public QQuickPaintedItem
2325

2426
public:
2527
NodeCore();
28+
2629
QColor backgroundColor() const;
2730
QColor highlightColor()const;
2831
QColor panelColor()const;
@@ -33,12 +36,18 @@ class NodeCore : public QQuickPaintedItem
3336
QFont titleFont()const;
3437
QList<Port> inputPort;
3538
QList<Port> outputPort;
39+
QList<Label> labelList;
40+
QList<CheckBox> checkBoxList;
41+
QList<NumberBox> numberBoxList;
42+
3643

3744
protected:
3845
void paint(QPainter*) override;
3946
void mouseMoveEvent(QMouseEvent*)override;
4047
void mousePressEvent(QMouseEvent*) override;
4148
void mouseReleaseEvent(QMouseEvent*) override;
49+
void focusOutEvent(QFocusEvent*) override;
50+
void keyPressEvent(QKeyEvent *)override;
4251

4352
signals:
4453

@@ -73,23 +82,33 @@ public slots:
7382
void DrawBody(QPainter*);
7483
void DrawTitle(QPainter*);
7584
void DrawPorts(QPainter*);
85+
void DrawLabels(QPainter*);
86+
void DrawCheckBoxes(QPainter*);
87+
void DrawNumberBoxes(QPainter*);
88+
7689
void DrawRopes();
7790
bool IsMouseOnHeader(QPoint);
91+
7892
Port* GetClickedPort(QPoint);
93+
CheckBox* GetClickedCheckBox(QPoint);
94+
NumberBox* GetClickedNumberBox(QPoint);
7995

8096
QPoint ConvertQPoint(QPointF);
8197
Port* GetPortNearestAtPosition(QPoint);
8298
void BindPort(Port*,Port*);
8399

84100
Port* currentPort;
101+
NumberBox* currentNumberBox=nullptr;
85102

86103
void PortClickHelper(QPoint);
104+
void CheckBoxClickHelper(QPoint);
105+
void NumberBoxClickHelper(QPoint);
106+
87107
void PortLineMoveHelper(QPoint);
88108
void ReleasePortTargeter(QPoint);
89109
bool FindInList(QList<Port*>,Port*);
90110

91111
void ConnectionRemover();
92-
93112
BlackBoard* Parent();
94113
};
95114

0 commit comments

Comments
 (0)