Update hide functions

Now hiding unvisited items is available
This commit is contained in:
Linloir 2021-12-06 10:22:19 +08:00
parent dd1fc7f34b
commit f735ff31d4
4 changed files with 156 additions and 10 deletions

View File

@ -241,6 +241,26 @@ void MyGraphicsView::RemoveArc(MyGraphicsLineItem *line){
line->remove(); line->remove();
} }
void MyGraphicsView::HideUnvisited(){
for(int i = 0; i < vexes.size(); i++){
if(!vexes[i]->isVisited())
vexes[i]->itemHide();
}
for(int i = 0; i < lines.size(); i++){
if(!lines[i]->isVisited())
lines[i]->itemHide();
}
}
void MyGraphicsView::ShowUnvisited(){
for(int i = 0; i < vexes.size(); i++){
vexes[i]->itemShow();
}
for(int i = 0; i < lines.size(); i++){
lines[i]->itemShow();
}
}
void MyGraphicsView::SaveToFile(QTextStream &ts){ void MyGraphicsView::SaveToFile(QTextStream &ts){
//vexes //vexes
ts << vexes.size() << "\n"; ts << vexes.size() << "\n";
@ -487,12 +507,16 @@ void MyGraphicsVexItem::visit(bool visited){
} }
}); });
connect(visitEffect, &QTimeLine::stateChanged, this, [=](){ connect(visitEffect, &QTimeLine::stateChanged, this, [=](){
if(visitEffect->state() == QTimeLine::Running) if(visitEffect->state() == QTimeLine::Running){
itemShow();
this->state |= ON_VISIT;
emit logAdded(new viewLog("[Vex] | \""+nameText+"\" set visited")); emit logAdded(new viewLog("[Vex] | \""+nameText+"\" set visited"));
}
}); });
emit addAnimation(visitEffect); emit addAnimation(visitEffect);
} }
else{ else{
state &= ~ON_VISIT;
if(state & ON_SELECTED){ if(state & ON_SELECTED){
this->setBrush(selBrush); this->setBrush(selBrush);
if(tag) if(tag)
@ -506,6 +530,38 @@ void MyGraphicsVexItem::visit(bool visited){
} }
} }
void MyGraphicsVexItem::itemHide(){
nameTag->setBrush(QColor(0, 0, 0, 0));
if(tag){
QBrush brush = tag->brush();
QColor color = brush.color();
color.setAlpha(0);
brush.setColor(color);
tag->setBrush(brush);
}
QBrush brush = this->brush();
QColor color = brush.color();
color.setAlpha(0);
brush.setColor(color);
this->setBrush(brush);
}
void MyGraphicsVexItem::itemShow(){
nameTag->setBrush(QColor(0, 0, 0));
if(tag){
QBrush brush = tag->brush();
QColor color = brush.color();
color.setAlpha(255);
brush.setColor(color);
tag->setBrush(brush);
}
QBrush brush = this->brush();
QColor color = brush.color();
color.setAlpha(255);
brush.setColor(color);
this->setBrush(brush);
}
void MyGraphicsVexItem::access(const QString &hint, bool isAccess){ void MyGraphicsVexItem::access(const QString &hint, bool isAccess){
if(isAccess){ if(isAccess){
if(!tag) if(!tag)
@ -540,8 +596,10 @@ void MyGraphicsVexItem::access(const QString &hint, bool isAccess){
} }
}); });
connect(accessEffect, &QTimeLine::stateChanged, this, [=](){ connect(accessEffect, &QTimeLine::stateChanged, this, [=](){
if(accessEffect->state() == QTimeLine::Running) if(accessEffect->state() == QTimeLine::Running){
itemShow();
emit logAdded(new viewLog("[Vex] | \""+nameText+"\" accessed with hint "+hint)); emit logAdded(new viewLog("[Vex] | \""+nameText+"\" accessed with hint "+hint));
}
}); });
emit addAnimation(accessEffect); emit addAnimation(accessEffect);
} }
@ -602,6 +660,7 @@ void MyGraphicsVexItem::onLeftClick(QPointF position){
return; return;
if(state & (ON_LEFT_CLICK | ON_RIGHT_CLICK)) if(state & (ON_LEFT_CLICK | ON_RIGHT_CLICK))
return; return;
itemShow();
if(this->contains(position)){ if(this->contains(position)){
emit selected(this); emit selected(this);
state |= ON_LEFT_CLICK; state |= ON_LEFT_CLICK;
@ -629,6 +688,7 @@ void MyGraphicsVexItem::onRightClick(QPointF position){
return; return;
if(state & (ON_LEFT_CLICK | ON_RIGHT_CLICK)) if(state & (ON_LEFT_CLICK | ON_RIGHT_CLICK))
return; return;
itemShow();
if(this->contains(position)){ if(this->contains(position)){
emit selected(this); emit selected(this);
state |= ON_RIGHT_CLICK; state |= ON_RIGHT_CLICK;
@ -920,6 +980,7 @@ void MyGraphicsLineItem::onLeftClick(QPointF position){
return; return;
if(state & ON_VISIT) if(state & ON_VISIT)
visit(false); visit(false);
itemShow();
if(this->contains(position)){ if(this->contains(position)){
emit selected(this); emit selected(this);
onClickEffect(); onClickEffect();
@ -946,6 +1007,7 @@ void MyGraphicsLineItem::onRightClick(QPointF position){
return; return;
if(state & ON_VISIT) if(state & ON_VISIT)
visit(false); visit(false);
itemShow();
if(this->contains(position)){ if(this->contains(position)){
emit selected(this); emit selected(this);
onClickEffect(); onClickEffect();
@ -981,9 +1043,9 @@ void MyGraphicsLineItem::onMouseRelease(){
} }
} }
void MyGraphicsLineItem::visit(bool visited){ void MyGraphicsLineItem::visit(bool visit){
if(visited){ if(visit){
state |= ON_VISIT; //state |= ON_VISIT;
QTimeLine *visitEffect = new QTimeLine; QTimeLine *visitEffect = new QTimeLine;
visitEffect->setDuration(1000); visitEffect->setDuration(1000);
visitEffect->setFrameRange(0, 200); visitEffect->setFrameRange(0, 200);
@ -1005,6 +1067,7 @@ void MyGraphicsLineItem::visit(bool visited){
newLine2->setZValue(this->zValue() - 2); newLine2->setZValue(this->zValue() - 2);
scene()->addItem(newLine2); scene()->addItem(newLine2);
} }
this->state |= ON_VISIT;
emit logAdded(new viewLog("[Arc] | Arc \""+startVex->Text()+"\" -> \""+endVex->Text()+"\" set visited")); emit logAdded(new viewLog("[Arc] | Arc \""+startVex->Text()+"\" -> \""+endVex->Text()+"\" set visited"));
} }
else{ else{
@ -1028,6 +1091,68 @@ void MyGraphicsLineItem::visit(bool visited){
} }
} }
void MyGraphicsLineItem::itemHide(){
if(line1){
QPen pen = line1->pen();
QColor color = pen.color();
color.setAlpha(0);
pen.setColor(color);
line1->setPen(pen);
}
if(line2){
QPen pen = line2->pen();
QColor color = pen.color();
color.setAlpha(0);
pen.setColor(color);
line2->setPen(pen);
}
if(arrow){
QPen pen = arrow->pen();
QColor color = pen.color();
color.setAlpha(0);
pen.setColor(color);
arrow->setPen(pen);
}
if(textItem){
QBrush brush = textItem->brush();
QColor color = brush.color();
color.setAlpha(0);
brush.setColor(color);
textItem->setBrush(brush);
}
}
void MyGraphicsLineItem::itemShow(){
if(line1){
QPen pen = line1->pen();
QColor color = pen.color();
color.setAlpha(255);
pen.setColor(color);
line1->setPen(pen);
}
if(line2){
QPen pen = line2->pen();
QColor color = pen.color();
color.setAlpha(255);
pen.setColor(color);
line2->setPen(pen);
}
if(arrow){
QPen pen = arrow->pen();
QColor color = pen.color();
color.setAlpha(255);
pen.setColor(color);
arrow->setPen(pen);
}
if(textItem){
QBrush brush = textItem->brush();
QColor color = brush.color();
color.setAlpha(255);
brush.setColor(color);
textItem->setBrush(brush);
}
}
void MyGraphicsLineItem::remove(){ void MyGraphicsLineItem::remove(){
startVex->removeStartLine(this); startVex->removeStartLine(this);
endVex->removeEndLine(this); endVex->removeEndLine(this);

View File

@ -126,6 +126,8 @@ public:
void RemoveVex(MyGraphicsVexItem *vex); void RemoveVex(MyGraphicsVexItem *vex);
void RemoveArc(MyGraphicsLineItem *line); void RemoveArc(MyGraphicsLineItem *line);
void HideUnvisited();
void ShowUnvisited();
void setAniRate(qreal rate){speedRate = rate;} void setAniRate(qreal rate){speedRate = rate;}
void setType(int _type){type = _type;} void setType(int _type){type = _type;}
@ -185,7 +187,7 @@ private:
static unsigned int internalID; static unsigned int internalID;
QBrush regBrush = QBrush(QColor(58, 143, 192)); QBrush regBrush = QBrush(QColor(58, 143, 192));
QBrush selBrush = QBrush(QColor(208, 90, 110)); QBrush selBrush = QBrush(QColor(208, 90, 110));
QBrush visitedBrush = QBrush(QColor(93, 172, 129)); QBrush visitedBrush = QBrush(QColor(0, 137, 108));
QBrush accessBrush = QBrush(QColor(152, 109, 178)); QBrush accessBrush = QBrush(QColor(152, 109, 178));
QPointF center; QPointF center;
@ -227,6 +229,8 @@ public:
void select(); void select();
void visit(bool visited = true); void visit(bool visited = true);
void access(const QString &hint = "", bool isAccess = true); void access(const QString &hint = "", bool isAccess = true);
void itemHide();
void itemShow();
QString Text(){return nameText;} QString Text(){return nameText;}
void setText(const QString & text){nameTag->setText(text);nameText = text;} void setText(const QString & text){nameTag->setText(text);nameText = text;}
void addStartLine(MyGraphicsLineItem *line){linesStartWith.push_back(line);} void addStartLine(MyGraphicsLineItem *line){linesStartWith.push_back(line);}
@ -237,6 +241,7 @@ public:
bool equalTo(MyGraphicsVexItem *v){return id == v->id;} bool equalTo(MyGraphicsVexItem *v){return id == v->id;}
int type() const override {return Type;} int type() const override {return Type;}
bool isVisited(){return state & ON_VISIT;}
qreal getRadius() {return radius;} qreal getRadius() {return radius;}
QString getData(){return QString::asprintf("%g %g %g\n", center.x(), center.y(), radius)+nameText;} QString getData(){return QString::asprintf("%g %g %g\n", center.x(), center.y(), radius)+nameText;}
@ -295,7 +300,7 @@ private:
QColor defaultColor = QColor(125, 185, 222); QColor defaultColor = QColor(125, 185, 222);
QColor hoverColor = QColor(0, 98, 132); QColor hoverColor = QColor(0, 98, 132);
QColor selColor = QColor(208, 90, 110); QColor selColor = QColor(208, 90, 110);
QColor visitColor = QColor(93, 172, 129); QColor visitColor = QColor(0, 137, 108);
QColor accessColor = QColor(178, 143, 206); QColor accessColor = QColor(178, 143, 206);
QPen defaultPen; QPen defaultPen;
QPen curPen; QPen curPen;
@ -345,11 +350,14 @@ public:
MyGraphicsVexItem* edVex(){return endVex;} MyGraphicsVexItem* edVex(){return endVex;}
QString weightText(){return text;} QString weightText(){return text;}
void visit(bool visited = true); void visit(bool visit = true);
void itemHide();
void itemShow();
void remove(); void remove();
void access(); void access();
int type() const override {return Type;} int type() const override {return Type;}
bool isVisited(){return state & ON_VISIT;}
signals: signals:
void setHover(bool in = true); void setHover(bool in = true);

View File

@ -52,18 +52,22 @@ void MainWindow::Init(){
/* Create about page */ /* Create about page */
defaultSettingsPage = new SlidePage(cornerRadius, "ABOUT", ui->mainWidget); defaultSettingsPage = new SlidePage(cornerRadius, "ABOUT", ui->mainWidget);
textInputItem *version = new textInputItem("version", defaultSettingsPage); textInputItem *version = new textInputItem("version", defaultSettingsPage);
version->setValue("1.2-beta"); version->setValue("1.3-beta");
version->setEnabled(false); version->setEnabled(false);
textInputItem *updateDate = new textInputItem("last-upd", defaultSettingsPage); textInputItem *updateDate = new textInputItem("last-upd", defaultSettingsPage);
updateDate->setValue("2021/12/6"); updateDate->setValue("2021/12/6 10:14");
updateDate->setEnabled(false); updateDate->setEnabled(false);
textInputItem *Author = new textInputItem("author", defaultSettingsPage); textInputItem *Author = new textInputItem("author", defaultSettingsPage);
Author->setValue("Linloir | Made with love"); Author->setValue("Linloir | Made with love");
Author->setEnabled(false); Author->setEnabled(false);
textInputItem *lic = new textInputItem("lic", defaultSettingsPage);
lic->setValue("MIT License");
lic->setEnabled(false);
textInputItem *GitHub = new textInputItem("git", defaultSettingsPage); textInputItem *GitHub = new textInputItem("git", defaultSettingsPage);
GitHub->setValue("github.com/Linloir"); GitHub->setValue("github.com/Linloir");
GitHub->setEnabled(false); GitHub->setEnabled(false);
defaultSettingsPage->AddContent(GitHub); defaultSettingsPage->AddContent(GitHub);
defaultSettingsPage->AddContent(lic);
defaultSettingsPage->AddContent(Author); defaultSettingsPage->AddContent(Author);
defaultSettingsPage->AddContent(updateDate); defaultSettingsPage->AddContent(updateDate);
defaultSettingsPage->AddContent(version); defaultSettingsPage->AddContent(version);

View File

@ -108,6 +108,12 @@ void MyCanvas::CreateSettings(int radius){
textInputItem *redesc = new textInputItem("Detail", this); textInputItem *redesc = new textInputItem("Detail", this);
redesc->setValue(canvasDescription); redesc->setValue(canvasDescription);
connect(redesc, &textInputItem::textEdited, this, [=](QString text){canvasDescription = text; emit descChanged(text);}); connect(redesc, &textInputItem::textEdited, this, [=](QString text){canvasDescription = text; emit descChanged(text);});
textButton *hideBtn = new textButton("Hide Unvisited Items", this);
connect(hideBtn, &textButton::clicked, this, [=](){view->HideUnvisited();});
textButton *showBtn = new textButton("Show Unvisited Items", this);
connect(showBtn, &textButton::clicked, this, [=](){view->ShowUnvisited();});
QWidget *whiteSpace2 = new QWidget(this);
whiteSpace2->setFixedHeight(30);
textButton *saveBtn = new textButton("Save to file", this); textButton *saveBtn = new textButton("Save to file", this);
connect(saveBtn, &textButton::clicked, this, [=](){ connect(saveBtn, &textButton::clicked, this, [=](){
QString savePath = QFileDialog::getSaveFileName(this, tr("Save map"), " ", tr("Map file(*.map)")); QString savePath = QFileDialog::getSaveFileName(this, tr("Save map"), " ", tr("Map file(*.map)"));
@ -118,6 +124,9 @@ void MyCanvas::CreateSettings(int radius){
connect(delBtn, &textButton::clicked, this, [=](){emit setDel(this);}); connect(delBtn, &textButton::clicked, this, [=](){emit setDel(this);});
settings->AddContent(delBtn); settings->AddContent(delBtn);
settings->AddContent(saveBtn); settings->AddContent(saveBtn);
settings->AddContent(whiteSpace2);
settings->AddContent(showBtn);
settings->AddContent(hideBtn);
settings->AddContent(dfsSetting); settings->AddContent(dfsSetting);
settings->AddContent(dirSetting); settings->AddContent(dirSetting);
settings->AddContent(structureSetting); settings->AddContent(structureSetting);