diff --git a/graph_view.cpp b/graph_view.cpp index 4209395..3ffd417 100644 --- a/graph_view.cpp +++ b/graph_view.cpp @@ -241,6 +241,26 @@ void MyGraphicsView::RemoveArc(MyGraphicsLineItem *line){ 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){ //vexes ts << vexes.size() << "\n"; @@ -487,12 +507,16 @@ void MyGraphicsVexItem::visit(bool visited){ } }); 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 addAnimation(visitEffect); } else{ + state &= ~ON_VISIT; if(state & ON_SELECTED){ this->setBrush(selBrush); 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){ if(isAccess){ if(!tag) @@ -540,8 +596,10 @@ void MyGraphicsVexItem::access(const QString &hint, bool isAccess){ } }); 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 addAnimation(accessEffect); } @@ -602,6 +660,7 @@ void MyGraphicsVexItem::onLeftClick(QPointF position){ return; if(state & (ON_LEFT_CLICK | ON_RIGHT_CLICK)) return; + itemShow(); if(this->contains(position)){ emit selected(this); state |= ON_LEFT_CLICK; @@ -629,6 +688,7 @@ void MyGraphicsVexItem::onRightClick(QPointF position){ return; if(state & (ON_LEFT_CLICK | ON_RIGHT_CLICK)) return; + itemShow(); if(this->contains(position)){ emit selected(this); state |= ON_RIGHT_CLICK; @@ -920,6 +980,7 @@ void MyGraphicsLineItem::onLeftClick(QPointF position){ return; if(state & ON_VISIT) visit(false); + itemShow(); if(this->contains(position)){ emit selected(this); onClickEffect(); @@ -946,6 +1007,7 @@ void MyGraphicsLineItem::onRightClick(QPointF position){ return; if(state & ON_VISIT) visit(false); + itemShow(); if(this->contains(position)){ emit selected(this); onClickEffect(); @@ -981,9 +1043,9 @@ void MyGraphicsLineItem::onMouseRelease(){ } } -void MyGraphicsLineItem::visit(bool visited){ - if(visited){ - state |= ON_VISIT; +void MyGraphicsLineItem::visit(bool visit){ + if(visit){ + //state |= ON_VISIT; QTimeLine *visitEffect = new QTimeLine; visitEffect->setDuration(1000); visitEffect->setFrameRange(0, 200); @@ -1005,6 +1067,7 @@ void MyGraphicsLineItem::visit(bool visited){ newLine2->setZValue(this->zValue() - 2); scene()->addItem(newLine2); } + this->state |= ON_VISIT; emit logAdded(new viewLog("[Arc] | Arc \""+startVex->Text()+"\" -> \""+endVex->Text()+"\" set visited")); } 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(){ startVex->removeStartLine(this); endVex->removeEndLine(this); diff --git a/graph_view.h b/graph_view.h index 53d1940..23fe232 100644 --- a/graph_view.h +++ b/graph_view.h @@ -126,6 +126,8 @@ public: void RemoveVex(MyGraphicsVexItem *vex); void RemoveArc(MyGraphicsLineItem *line); + void HideUnvisited(); + void ShowUnvisited(); void setAniRate(qreal rate){speedRate = rate;} void setType(int _type){type = _type;} @@ -185,7 +187,7 @@ private: static unsigned int internalID; QBrush regBrush = QBrush(QColor(58, 143, 192)); 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)); QPointF center; @@ -227,6 +229,8 @@ public: void select(); void visit(bool visited = true); void access(const QString &hint = "", bool isAccess = true); + void itemHide(); + void itemShow(); QString Text(){return nameText;} void setText(const QString & text){nameTag->setText(text);nameText = text;} void addStartLine(MyGraphicsLineItem *line){linesStartWith.push_back(line);} @@ -237,6 +241,7 @@ public: bool equalTo(MyGraphicsVexItem *v){return id == v->id;} int type() const override {return Type;} + bool isVisited(){return state & ON_VISIT;} qreal getRadius() {return radius;} 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 hoverColor = QColor(0, 98, 132); QColor selColor = QColor(208, 90, 110); - QColor visitColor = QColor(93, 172, 129); + QColor visitColor = QColor(0, 137, 108); QColor accessColor = QColor(178, 143, 206); QPen defaultPen; QPen curPen; @@ -345,11 +350,14 @@ public: MyGraphicsVexItem* edVex(){return endVex;} QString weightText(){return text;} - void visit(bool visited = true); + void visit(bool visit = true); + void itemHide(); + void itemShow(); void remove(); void access(); int type() const override {return Type;} + bool isVisited(){return state & ON_VISIT;} signals: void setHover(bool in = true); diff --git a/mainwindow.cpp b/mainwindow.cpp index 2f150ca..63ec6e8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -52,18 +52,22 @@ void MainWindow::Init(){ /* Create about page */ defaultSettingsPage = new SlidePage(cornerRadius, "ABOUT", ui->mainWidget); textInputItem *version = new textInputItem("version", defaultSettingsPage); - version->setValue("1.2-beta"); + version->setValue("1.3-beta"); version->setEnabled(false); textInputItem *updateDate = new textInputItem("last-upd", defaultSettingsPage); - updateDate->setValue("2021/12/6"); + updateDate->setValue("2021/12/6 10:14"); updateDate->setEnabled(false); textInputItem *Author = new textInputItem("author", defaultSettingsPage); Author->setValue("Linloir | Made with love"); Author->setEnabled(false); + textInputItem *lic = new textInputItem("lic", defaultSettingsPage); + lic->setValue("MIT License"); + lic->setEnabled(false); textInputItem *GitHub = new textInputItem("git", defaultSettingsPage); GitHub->setValue("github.com/Linloir"); GitHub->setEnabled(false); defaultSettingsPage->AddContent(GitHub); + defaultSettingsPage->AddContent(lic); defaultSettingsPage->AddContent(Author); defaultSettingsPage->AddContent(updateDate); defaultSettingsPage->AddContent(version); diff --git a/mycanvas.cpp b/mycanvas.cpp index e44d123..5524d21 100644 --- a/mycanvas.cpp +++ b/mycanvas.cpp @@ -108,6 +108,12 @@ void MyCanvas::CreateSettings(int radius){ textInputItem *redesc = new textInputItem("Detail", this); redesc->setValue(canvasDescription); 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); connect(saveBtn, &textButton::clicked, this, [=](){ 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);}); settings->AddContent(delBtn); settings->AddContent(saveBtn); + settings->AddContent(whiteSpace2); + settings->AddContent(showBtn); + settings->AddContent(hideBtn); settings->AddContent(dfsSetting); settings->AddContent(dirSetting); settings->AddContent(structureSetting);