From 8aa84380648ff4d51f192929da6c42c1f15cebd4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Feb 2015 13:47:53 +0200 Subject: [PATCH] Disable label if pattern piece disabled. --HG-- branch : feature --- src/app/tools/drawTools/vtoolpoint.cpp | 6 +----- src/app/visualization/vgraphicssimpletextitem.cpp | 15 +++++++++++++++ src/app/visualization/vgraphicssimpletextitem.h | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 53025c402..99bae27da 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -50,9 +50,7 @@ VToolPoint::VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsIte namePoint = new VGraphicsSimpleTextItem(this); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::ShowContextMenu); connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VToolPoint::DeleteFromLabel); - namePoint->setBrush(Qt::black); lineName = new QGraphicsLineItem(this); - lineName->setPen(QPen(Qt::black)); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -136,9 +134,7 @@ void VToolPoint::ChangedActivDraw(const QString &newName) { VDrawTool::ChangedActivDraw(newName); this->setEnabled(nameActivDraw == newName); - namePoint->setBrush(QBrush(currentColor)); - lineName->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + namePoint->setEnabled(nameActivDraw == newName); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vgraphicssimpletextitem.cpp b/src/app/visualization/vgraphicssimpletextitem.cpp index 49921e86b..85f07a71d 100644 --- a/src/app/visualization/vgraphicssimpletextitem.cpp +++ b/src/app/visualization/vgraphicssimpletextitem.cpp @@ -83,6 +83,21 @@ void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic QGraphicsSimpleTextItem::paint(painter, &myOption, widget); } +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsSimpleTextItem::setEnabled(bool enabled) +{ + QGraphicsSimpleTextItem::setEnabled(enabled); + const QPalette palet = this->scene()->palette(); + if (enabled) + { + setBrush(palet.brush(QPalette::Active, QPalette::Text)); + } + else + { + setBrush(palet.brush(QPalette::Disabled, QPalette::Text)); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief itemChange handle item change. diff --git a/src/app/visualization/vgraphicssimpletextitem.h b/src/app/visualization/vgraphicssimpletextitem.h index daf3c9297..3868e33f6 100644 --- a/src/app/visualization/vgraphicssimpletextitem.h +++ b/src/app/visualization/vgraphicssimpletextitem.h @@ -47,6 +47,8 @@ public: virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Vis::GraphicsSimpleTextItem)}; + + void setEnabled(bool enabled); signals: /** * @brief NameChangePosition emit when label change position.