[Uml-devel] branches/work/soc-umbrello/umbrello/widgets
Andi Fischer
andi.fischer at hispeed.ch
Sun Mar 27 01:34:21 UTC 2011
SVN commit 1226134 by fischer:
Visibility of the expander boxes for attributes and operations changed - only visible when mouse hovered over the classifier.
M +57 -15 classifierwidget.cpp
M +3 -0 classifierwidget.h
M +0 -1 umlwidget.h
--- branches/work/soc-umbrello/umbrello/widgets/classifierwidget.cpp #1226133:1226134
@@ -63,6 +63,11 @@
m_operationExpanderBox = new ExpanderBox(false, this);
connect(m_operationExpanderBox, SIGNAL(expansionToggled(bool)), this, SLOT(slotShowOperations(bool)));
+ m_attributeExpanderBox->setVisible(false);
+ m_operationExpanderBox->setVisible(false);
+
+ setAcceptHoverEvents(true); // to show and hide the expander box handlers
+
// Null initially
m_dummyAttributeItem = m_dummyOperationItem = 0;
m_lineItem2Index = InvalidIndex;
@@ -85,6 +90,8 @@
m_visualProperties = ShowOperations | ShowVisibility | ShowStereotype;
setShowStereotype(true);
}
+
+ DEBUG_REGISTER(DBG_SRC);
}
/**
@@ -98,7 +105,9 @@
}
}
-/// @return the UMLClassifier which this ClassifierWidget represents.
+/**
+ * @return the UMLClassifier which this ClassifierWidget represents.
+ */
UMLClassifier *ClassifierWidget::classifier() const
{
return static_cast<UMLClassifier*>(umlObject());
@@ -231,7 +240,7 @@
oppositeStatus = !visualProperty(property);
}
- uDebug() << "VisualProperty:" << property << "to opposite status " << oppositeStatus;
+ DEBUG(DBG_SRC) << "VisualProperty: " << property << " to opposite status " << oppositeStatus;
setVisualProperty(property, oppositeStatus);
}
@@ -419,16 +428,18 @@
void ClassifierWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget *)
{
QPen pen(lineColor(), lineWidth());
+
+ if (shouldDrawAsCircle()) {
painter->setPen(pen);
painter->setBrush(brush());
-
- if (shouldDrawAsCircle()) {
// m_classifierRect represents circle geometry when shouldDrawAsCircle is true.
painter->drawEllipse(m_classifierRect);
}
else {
// The elements not to be drawn will have null dimension and
// hence it effectively is not drawn. (automatic ;) )
+ painter->setPen(pen);
+ painter->setBrush(brush());
painter->drawRoundedRect(m_classifierRect, 2, 2);
painter->drawLines(m_classifierLines, 2);
@@ -488,7 +499,7 @@
}
setMinimumSize(totalMinSize, sizeHintOption);
- setSize(totalMinSize); //:fischer:
+ setSize(totalMinSize);
UMLWidget::updateGeometry();
}
@@ -578,26 +589,25 @@
attribOpGroup->setGroupGeometry(attribOpGeometry);
const int cnt = attribOpGroup->textItemCount();
- qreal expanderDistance = 4;
+ qreal expanderDistance = -11;
bool showNameOnly = (!visualProperty(ShowAttributes) && !visualProperty(ShowOperations)
&& !visualProperty(ShowStereotype) && !shouldDrawAsCircle());
if (!showNameOnly && !shouldDrawAsCircle()) {
qreal y = textItemGroupAt(HeaderGroupIndex)->groupGeometry().bottom();
m_classifierLines[0].setLine(m_classifierRect.left(), y, m_classifierRect.right(), y);
qreal expanderX = rect().left() -
- m_attributeExpanderBox->rect().width() -
- expanderDistance;
+ m_attributeExpanderBox->rect().width() - expanderDistance;
m_attributeExpanderBox->setPos(expanderX, y);
}
if (cnt > m_lineItem2Index) {
TextItem *item = attribOpGroup->textItemAt(m_lineItem2Index);
qreal y = item->mapToParent(item->boundingRect().bottomLeft()).y();
m_classifierLines[1].setLine(m_classifierRect.left(), y, m_classifierRect.right(), y);
- qreal expanderX = rect().left() - m_operationExpanderBox->rect().width() -
- expanderDistance;
+ qreal expanderX = rect().left() -
+ m_operationExpanderBox->rect().width() - expanderDistance;
m_operationExpanderBox->setPos(expanderX, y);
}
- if (InvalidIndex == m_lineItem2Index) { // attributes and operations invisible //:fischer:
+ if (InvalidIndex == m_lineItem2Index) { // attributes and operations invisible
QPointF pos = m_attributeExpanderBox->pos();
m_operationExpanderBox->setPos(pos.x(), pos.y() + 12);
}
@@ -692,7 +702,6 @@
// Update expander box to reflect current state and also visibility
m_attributeExpanderBox->setExpanded(visualProperty(ShowAttributes));
- m_attributeExpanderBox->setVisible(!visualProperty(DrawAsCircle) && !umlC->isInterface());
const QString dummyText;
// Setup line and dummies.
@@ -734,7 +743,6 @@
}
}
m_operationExpanderBox->setExpanded(visualProperty(ShowOperations));
- m_operationExpanderBox->setVisible(!visualProperty(DrawAsCircle));
if (!showNameOnly) {
if (!shouldDrawAsCircle() && (visibleOperations == 0 || !visualProperty(ShowOperations))) {
@@ -865,13 +873,17 @@
}
}
-/// Slot to show/hide attributes based on \a state.
+/**
+ * Slot to show/hide attributes based on \a state.
+ */
void ClassifierWidget::slotShowAttributes(bool state)
{
setVisualProperty(ShowAttributes, state);
}
-/// Slot to show/hide operations based on \a state.
+/**
+ * Slot to show/hide operations based on \a state.
+ */
void ClassifierWidget::slotShowOperations(bool state)
{
setVisualProperty(ShowOperations, state);
@@ -896,3 +908,33 @@
m_lineItem2Index = InvalidIndex;
m_classifierLines[0] = m_classifierLines[1] = QLineF();
}
+
+/**
+ * Event handler for hover enter events.
+ */
+void ClassifierWidget::hoverEnterEvent(QGraphicsSceneHoverEvent * event)
+{
+ Q_UNUSED(event);
+ if (!visualProperty(DrawAsCircle)) {
+ UMLClassifier* umlC = classifier();
+ if (umlC && !umlC->isInterface()) {
+ m_attributeExpanderBox->setVisible(true);
+ }
+ m_operationExpanderBox->setVisible(true);
+ }
+}
+
+/**
+ * Event handler for hover leave events.
+ */
+void ClassifierWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
+{
+ Q_UNUSED(event);
+ if (!visualProperty(DrawAsCircle)) {
+ UMLClassifier* umlC = classifier();
+ if (umlC && !umlC->isInterface()) {
+ m_attributeExpanderBox->setVisible(false);
+ }
+ m_operationExpanderBox->setVisible(false);
+ }
+}
--- branches/work/soc-umbrello/umbrello/widgets/classifierwidget.h #1226133:1226134
@@ -102,6 +102,9 @@
virtual void updateTextItemGroups();
virtual QVariant attributeChange(WidgetAttributeChange change, const QVariant& oldValue);
+ virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
+ virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
+
public Q_SLOTS:
virtual void slotMenuSelection(QAction* action);
--- branches/work/soc-umbrello/umbrello/widgets/umlwidget.h #1226133:1226134
@@ -170,7 +170,6 @@
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
-
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
TextItemGroup* createTextItemGroup();
More information about the umbrello-devel
mailing list