0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00
LimeReport/limereport/items/lrlayoutmarker.cpp

75 lines
2.0 KiB
C++
Raw Normal View History

2018-06-21 14:29:00 +03:00
#include "lrlayoutmarker.h"
2018-06-21 14:29:00 +03:00
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
2018-06-21 14:29:00 +03:00
namespace LimeReport {
2018-06-21 14:29:00 +03:00
LayoutMarker::LayoutMarker(BaseDesignIntf* layout, QGraphicsItem* parent):
QGraphicsItem(parent),
m_rect(0, 0, 30, 30),
m_color(Qt::red),
m_layout(layout)
{
2018-06-21 14:29:00 +03:00
setFlag(QGraphicsItem::ItemIsMovable);
}
void LayoutMarker::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
2018-06-21 14:29:00 +03:00
{
painter->save();
painter->setOpacity(Const::LAYOUT_MARKER_OPACITY);
painter->fillRect(boundingRect(), m_color);
2018-06-21 14:29:00 +03:00
painter->setRenderHint(QPainter::Antialiasing);
qreal size = (boundingRect().width() < boundingRect().height()) ? boundingRect().width()
: boundingRect().height();
2018-06-21 14:29:00 +03:00
if (m_layout->isSelected()) {
2018-06-21 14:29:00 +03:00
painter->setOpacity(1);
QRectF r = QRectF(0, 0, size, size);
2018-06-21 14:29:00 +03:00
painter->setBrush(Qt::white);
painter->setPen(Qt::white);
painter->drawEllipse(r.adjusted(5, 5, -5, -5));
2018-06-21 14:29:00 +03:00
painter->setBrush(m_color);
painter->drawEllipse(r.adjusted(7, 7, -7, -7));
2018-06-21 14:29:00 +03:00
}
painter->restore();
}
void LayoutMarker::setHeight(qreal height)
{
if (m_rect.height() != height) {
2018-06-21 14:29:00 +03:00
prepareGeometryChange();
m_rect.setHeight(height);
}
}
void LayoutMarker::setWidth(qreal width)
{
if (m_rect.width() != width) {
2018-06-21 14:29:00 +03:00
prepareGeometryChange();
m_rect.setWidth(width);
}
}
void LayoutMarker::setColor(QColor color)
{
if (m_color != color) {
2018-06-21 14:29:00 +03:00
m_color = color;
update(boundingRect());
}
}
void LayoutMarker::mousePressEvent(QGraphicsSceneMouseEvent* event)
2018-06-21 14:29:00 +03:00
{
if (event->button() == Qt::LeftButton) {
2018-06-21 14:29:00 +03:00
if (!(event->modifiers() & Qt::ControlModifier))
m_layout->scene()->clearSelection();
m_layout->setSelected(true);
// m_layout->setChildVisibility(false);
update(0, 0, boundingRect().width(), boundingRect().width());
2018-06-21 14:29:00 +03:00
}
}
} // namespace LimeReport