set text color with t, node color with c

master
Denes Matetelki 14 years ago
parent 0f21ae4faa
commit b26e01972c

@ -86,7 +86,14 @@ void GraphWidget::readContentFromXmlFile(const QString &fileName)
node->setPos(e.attribute("x").toFloat(), node->setPos(e.attribute("x").toFloat(),
e.attribute("y").toFloat()); e.attribute("y").toFloat());
node->setScale(e.attribute("scale").toFloat()); node->setScale(e.attribute("scale").toFloat());
node->setColor(QColor(e.attribute("bg_red").toFloat(),
e.attribute("bg_green").toFloat(),
e.attribute("bg_blue").toFloat(),
e.attribute("bg_alpha").toFloat()));
node->setTextColor(QColor(e.attribute("text_red").toFloat(),
e.attribute("text_green").toFloat(),
e.attribute("text_blue").toFloat(),
e.attribute("text_alpha").toFloat()));
m_nodeList.append(node); m_nodeList.append(node);
} }
} }
@ -129,7 +136,15 @@ void GraphWidget::writeContentToXmlFile(const QString &fileName)
cn.setAttribute( "x", QString::number(node->pos().x())); cn.setAttribute( "x", QString::number(node->pos().x()));
cn.setAttribute( "y", QString::number(node->pos().y())); cn.setAttribute( "y", QString::number(node->pos().y()));
cn.setAttribute( "htmlContent", node->toHtml()); cn.setAttribute( "htmlContent", node->toHtml());
cn.setAttribute("scale", QString::number(((QGraphicsTextItem*)node)->scale())); cn.setAttribute( "scale", QString::number(((QGraphicsTextItem*)node)->scale()));
cn.setAttribute( "bg_red", QString::number(node->color().red()));
cn.setAttribute( "bg_green", QString::number(node->color().green()));
cn.setAttribute( "bg_blue", QString::number(node->color().blue()));
cn.setAttribute( "bg_alpha", QString::number(node->color().alpha()));
cn.setAttribute( "text_red", QString::number(node->textColor().red()));
cn.setAttribute( "text_green", QString::number(node->textColor().green()));
cn.setAttribute( "text_blue", QString::number(node->textColor().blue()));
cn.setAttribute( "text_alpha", QString::number(node->textColor().alpha()));
nodes_root.appendChild(cn); nodes_root.appendChild(cn);
} }
@ -198,11 +213,13 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
// certain actions need an active node // certain actions need an active node
if (!m_activeNode && if (!m_activeNode &&
( event->key() == Qt::Key_Insert || // add new node ( event->key() == Qt::Key_Insert || // add new node
event->key() == Qt::Key_F2 || // edit node event->key() == Qt::Key_F2 || // edit node
event->key() == Qt::Key_Delete || // delete node event->key() == Qt::Key_Delete || // delete node
event->key() == Qt::Key_A || // add edge event->key() == Qt::Key_A || // add edge
event->key() == Qt::Key_D || // remove edge event->key() == Qt::Key_D || // remove edge
event->key() == Qt::Key_C || // node color
event->key() == Qt::Key_T || // node text color
( event->modifiers() & Qt::ControlModifier && // moving node ( event->modifiers() & Qt::ControlModifier && // moving node
( event->key() == Qt::Key_Up || ( event->key() == Qt::Key_Up ||
event->key() == Qt::Key_Down || event->key() == Qt::Key_Down ||
@ -348,9 +365,14 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
// delete node // delete node
case Qt::Key_Delete: case Qt::Key_Delete:
if (m_nodeList.size()==1) // if (m_nodeList.size()==1)
// {
// m_parent->statusBarMsg(tr("Last node cannot be deleted."));
// break;
// }
if (m_activeNode == m_nodeList.first())
{ {
m_parent->statusBarMsg(tr("Last node cannot be deleted.")); m_parent->statusBarMsg(tr("Base node cannot be deleted."));
break; break;
} }
@ -382,8 +404,27 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
case Qt::Key_C: case Qt::Key_C:
{ {
QColorDialog dialog(this); QColorDialog dialog(this);
dialog.setWindowTitle(tr("Select node color"));
dialog.setOption(QColorDialog::ShowAlphaChannel);
if (dialog.exec()) if (dialog.exec())
{
QColor color = dialog.selectedColor(); QColor color = dialog.selectedColor();
m_activeNode->setColor(color);
}
break;
}
case Qt::Key_T:
{
QColorDialog dialog(this);
dialog.setWindowTitle(tr("Select text color"));
dialog.setOption(QColorDialog::ShowAlphaChannel);
if (dialog.exec())
{
QColor color = dialog.selectedColor();
m_activeNode->setTextColor(color);
}
break; break;
} }

@ -65,6 +65,7 @@ private:
QString m_fileName; QString m_fileName;
static const QColor m_paper; static const QColor m_paper;
static const QColor m_gold;
}; };
#endif // GRAPHWIDGET_H #endif // GRAPHWIDGET_H

@ -10,14 +10,17 @@ const double Node::m_pi = 3.14159265358979323846264338327950288419717;
const double Node::m_oneAndHalfPi = Node::m_pi * 1.5; const double Node::m_oneAndHalfPi = Node::m_pi * 1.5;
const double Node::m_twoPi = Node::m_pi * 2.0; const double Node::m_twoPi = Node::m_pi * 2.0;
const QColor Node::m_orange(255,215,0); const QColor Node::m_gold(255,215,0);
const QColor Node::m_orange(255,102,0);
Node::Node(GraphWidget *parent) : Node::Node(GraphWidget *parent) :
m_graph(parent), m_graph(parent),
m_isActive(false), m_isActive(false),
m_number(-1), m_number(-1),
m_hasBorder(true), m_hasBorder(false),
m_numberIsSpecial(false) m_numberIsSpecial(false),
m_color(m_gold),
m_textColor(0,0,0)
{ {
setFlag(ItemIsMovable); setFlag(ItemIsMovable);
setFlag(ItemSendsGeometryChanges); setFlag(ItemSendsGeometryChanges);
@ -95,6 +98,18 @@ void Node::setEditable(const bool &editable)
setTextCursor(c); setTextCursor(c);
} }
void Node::setColor(const QColor &color)
{
m_color = color;
update();
}
void Node::setTextColor(const QColor &color)
{
m_textColor = color;
update();
}
void Node::scale(const qreal &factor) void Node::scale(const qreal &factor)
{ {
qDebug() << factor * QGraphicsTextItem::scale(); qDebug() << factor * QGraphicsTextItem::scale();
@ -281,8 +296,10 @@ void Node::paint(QPainter *painter,
painter->setPen(m_isActive ? Qt::red : Qt::blue) : painter->setPen(m_isActive ? Qt::red : Qt::blue) :
painter->setPen(Qt::transparent); painter->setPen(Qt::transparent);
if (m_isActive) m_isActive?
painter->setBrush(Node::m_orange); // painter->setBrush(Node::m_orange) :
painter->setBrush(m_color.darker(120)) :
painter->setBrush(m_color);
painter->drawRoundedRect(boundingRect(), 20.0, 15.0); painter->drawRoundedRect(boundingRect(), 20.0, 15.0);
} }
@ -290,6 +307,7 @@ void Node::paint(QPainter *painter,
// the text itself // the text itself
setDefaultTextColor(m_textColor);
QGraphicsTextItem::paint(painter, option, w); QGraphicsTextItem::paint(painter, option, w);

@ -24,6 +24,10 @@ public:
void setBorder(const bool &hasBorder); void setBorder(const bool &hasBorder);
void setActive(const bool &active = true); void setActive(const bool &active = true);
void setEditable(const bool &editable = true); void setEditable(const bool &editable = true);
void setColor(const QColor &color);
QColor color() const { return m_color; }
void setTextColor(const QColor &color);
QColor textColor() const { return m_textColor; }
void scale(const qreal &factor); void scale(const qreal &factor);
void showNumber(const int &number, const bool& show = true, void showNumber(const int &number, const bool& show = true,
@ -65,12 +69,15 @@ private:
int m_number; int m_number;
bool m_hasBorder; bool m_hasBorder;
bool m_numberIsSpecial; bool m_numberIsSpecial;
QColor m_color;
QColor m_textColor;
static const double m_pi; static const double m_pi;
static const double m_oneAndHalfPi; static const double m_oneAndHalfPi;
static const double m_twoPi; static const double m_twoPi;
static const QColor m_orange; static const QColor m_orange;
static const QColor m_gold;
}; };
#endif // NODE_H #endif // NODE_H

Loading…
Cancel
Save