Commit e5a17106 authored by Julius Künzel's avatar Julius Künzel
Browse files

Titler: Add ellipse item

parent 41846df3
Pipeline #54429 passed with stage
in 10 minutes and 30 seconds
......@@ -484,6 +484,40 @@ QVariant MyRectItem::itemChange(GraphicsItemChange change, const QVariant &value
return QGraphicsItem::itemChange(change, value);
}
MyEllipseItem::MyEllipseItem(QGraphicsItem *parent)
: QGraphicsEllipseItem(parent)
{
//Disabled because cache makes text cursor invisible and borders ugly
//setCacheMode(QGraphicsItem::ItemCoordinateCache);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
void MyEllipseItem::setRect(const QRectF &rectangle)
{
QGraphicsEllipseItem::setRect(rectangle);
if (m_ellipse != rectangle && !data(TitleDocument::Gradient).isNull()) {
m_ellipse = rectangle;
QLinearGradient gr = GradientWidget::gradientFromString(data(TitleDocument::Gradient).toString(), m_ellipse.width(), m_ellipse.height());
setBrush(QBrush(gr));
}
}
QVariant MyEllipseItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange && (scene() != nullptr)) {
QPoint newPos = value.toPoint();
if (QApplication::mouseButtons() == Qt::LeftButton && (qobject_cast<GraphicsSceneRectMove *>(scene()) != nullptr)) {
auto *customScene = qobject_cast<GraphicsSceneRectMove *>(scene());
int gridSize = customScene->gridSize();
int xV = (newPos.x() / gridSize) * gridSize;
int yV = (newPos.y() / gridSize) * gridSize;
newPos = QPoint(xV, yV);
}
return newPos;
}
return QGraphicsItem::itemChange(change, value);
}
MyPixmapItem::MyPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent)
: QGraphicsPixmapItem(pixmap, parent)
{
......@@ -563,6 +597,7 @@ void GraphicsSceneRectMove::setTool(TITLETOOL tool)
{
m_tool = tool;
switch (m_tool) {
case TITLE_ELLIPSE:
case TITLE_RECTANGLE:
setCursor(Qt::CrossCursor);
break;
......@@ -756,7 +791,7 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent *e)
t->setTextInteractionFlags(Qt::NoTextInteraction);
t->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setCursor(Qt::ClosedHandCursor);
} else if (item->type() == QGraphicsRectItem::Type || item->type() == QGraphicsSvgItem::Type || item->type() == QGraphicsPixmapItem::Type) {
} else if (item->type() == QGraphicsRectItem::Type || item->type() == QGraphicsEllipseItem::Type || item->type() == QGraphicsSvgItem::Type || item->type() == QGraphicsPixmapItem::Type) {
QRectF r1;
if (m_selectedItem->type() == QGraphicsRectItem::Type) {
r1 = ((QGraphicsRectItem *)m_selectedItem)->rect().normalized();
......@@ -792,7 +827,7 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent *e)
}
}
QGraphicsScene::mousePressEvent(e);
} else if (m_tool == TITLE_RECTANGLE) {
} else if (m_tool == TITLE_RECTANGLE || m_tool == TITLE_ELLIPSE) {
clearTextSelection();
m_sceneClickPoint = QPointF(xPos, yPos);
m_selectedItem = nullptr;
......@@ -859,8 +894,8 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
m_moveStarted = true;
}
if ((m_selectedItem != nullptr) && ((e->buttons() & Qt::LeftButton) != 0u)) {
if (m_selectedItem->type() == QGraphicsRectItem::Type || m_selectedItem->type() == QGraphicsSvgItem::Type ||
m_selectedItem->type() == QGraphicsPixmapItem::Type) {
if (m_selectedItem->type() == QGraphicsRectItem::Type || m_selectedItem->type() == QGraphicsEllipseItem::Type || m_selectedItem->type() == QGraphicsSvgItem::Type ||
m_selectedItem->type() == QGraphicsPixmapItem::Type) {
QRectF newrect;
if (m_selectedItem->type() == QGraphicsRectItem::Type) {
newrect = ((QGraphicsRectItem *)m_selectedItem)->rect();
......@@ -910,6 +945,23 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
gi->setRect(QRectF(QPointF(), newrect.bottomRight() - newrect.topLeft()));
return;
}
if (m_selectedItem->type() == QGraphicsEllipseItem::Type && m_resizeMode != NoResize) {
auto *gi = static_cast<MyEllipseItem *>(m_selectedItem);
// Resize using aspect ratio
if (!m_selectedItem->data(0).isNull()) {
// we want to keep aspect ratio
double hRatio = (double)newrect.width() / m_selectedItem->data(0).toInt();
double vRatio = (double)newrect.height() / m_selectedItem->data(1).toInt();
if (hRatio < vRatio) {
newrect.setHeight(m_selectedItem->data(1).toInt() * hRatio);
} else {
newrect.setWidth(m_selectedItem->data(0).toInt() * vRatio);
}
}
gi->setPos(newrect.topLeft());
gi->setRect(QRectF(QPointF(), newrect.bottomRight() - newrect.topLeft()));
return;
}
QGraphicsScene::mouseMoveEvent(e);
} else if (m_selectedItem->type() == QGraphicsTextItem::Type) {
auto *t = static_cast<MyTextItem *>(m_selectedItem);
......@@ -936,11 +988,16 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
setCursor(Qt::OpenHandCursor);
itemFound = true;
break;
} else if (g->type() == QGraphicsRectItem::Type && g->zValue() > -1000) {
} else if ((g->type() == QGraphicsRectItem::Type || g->type() == QGraphicsEllipseItem::Type) && g->zValue() > -1000) {
if (view == nullptr) {
continue;
}
QRectF r1 = ((const QGraphicsRectItem *)g)->rect().normalized();
QRectF r1;
if(g->type() == QGraphicsRectItem::Type) {
r1 = ((const QGraphicsRectItem *)g)->rect().normalized();
} else {
r1 = ((const QGraphicsEllipseItem *)g)->rect().normalized();
}
itemFound = true;
// Item mapped coordinates
......@@ -1014,6 +1071,22 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
m_resizeMode = BottomRight;
QGraphicsScene::mouseMoveEvent(e);
}
} else if (m_tool == TITLE_ELLIPSE && ((e->buttons() & Qt::LeftButton) != 0u)) {
if (m_selectedItem == nullptr) {
// create new rect item
QRectF r(0, 0, e->scenePos().x() - m_sceneClickPoint.x(), e->scenePos().y() - m_sceneClickPoint.y());
r = r.normalized();
auto *ellipse = new MyEllipseItem();
ellipse->setRect(QRectF(0, 0, r.width(), r.height()));
addItem(ellipse);
m_selectedItem = ellipse;
m_selectedItem->setPos(m_sceneClickPoint);
m_selectedItem->setSelected(true);
emit newEllipse(ellipse);
m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
m_resizeMode = BottomRight;
QGraphicsScene::mouseMoveEvent(e);
}
}
}
......
......@@ -27,7 +27,7 @@
#include <QGraphicsTextItem>
enum resizeModes { NoResize = 0, TopLeft, BottomLeft, TopRight, BottomRight, Left, Right, Up, Down };
enum TITLETOOL { TITLE_SELECT = 0, TITLE_RECTANGLE = 1, TITLE_TEXT = 2, TITLE_IMAGE = 3 };
enum TITLETOOL { TITLE_SELECT = 0, TITLE_RECTANGLE = 1, TITLE_TEXT = 2, TITLE_IMAGE = 3, TITLE_ELLIPSE = 4 };
class MyQGraphicsEffect : public QGraphicsEffect
{
......@@ -104,6 +104,19 @@ private:
QRectF m_rect;
};
class MyEllipseItem : public QGraphicsEllipseItem
{
public:
explicit MyEllipseItem(QGraphicsItem *parent = nullptr);
void setRect(const QRectF &rectangle);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
private:
QRectF m_ellipse;
};
class MyPixmapItem : public QGraphicsPixmapItem
{
public:
......@@ -171,6 +184,7 @@ signals:
void itemMoved();
void sceneZoom(bool);
void newRect(QGraphicsRectItem *);
void newEllipse(QGraphicsEllipseItem *);
void newText(MyTextItem *);
void actionFinished();
void doubleClickEvent();
......
......@@ -187,6 +187,21 @@ QDomDocument TitleDocument::xml(const QList<QGraphicsItem *> & items, int width,
content.setAttribute(QStringLiteral("gradient"), gradient);
}
break;
case 4:
e.setAttribute(QStringLiteral("type"), QStringLiteral("QGraphicsEllipseItem"));
content.setAttribute(QStringLiteral("rect"), rectFToString(static_cast<QGraphicsEllipseItem *>(item)->rect().normalized()));
content.setAttribute(QStringLiteral("pencolor"), colorToString(static_cast<QGraphicsEllipseItem *>(item)->pen().color()));
if (static_cast<QGraphicsEllipseItem *>(item)->pen() == Qt::NoPen) {
content.setAttribute(QStringLiteral("penwidth"), 0);
} else {
content.setAttribute(QStringLiteral("penwidth"), static_cast<QGraphicsEllipseItem *>(item)->pen().width());
}
content.setAttribute(QStringLiteral("brushcolor"), colorToString(static_cast<QGraphicsEllipseItem *>(item)->brush().color()));
gradient = item->data(TitleDocument::Gradient).toString();
if (!gradient.isEmpty()) {
content.setAttribute(QStringLiteral("gradient"), gradient);
}
break;
case 8:
e.setAttribute(QStringLiteral("type"), QStringLiteral("QGraphicsTextItem"));
t = static_cast<MyTextItem *>(item);
......@@ -569,6 +584,31 @@ int TitleDocument::loadFromXml(const QDomDocument &doc, QList<QGraphicsItem *> &
gitems.append(rec);
gitem = rec;
} else if (itemNode.attributes().namedItem(QStringLiteral("type")).nodeValue() == QLatin1String("QGraphicsEllipseItem")) {
QDomNamedNodeMap ellipseProperties = itemNode.namedItem(QStringLiteral("content")).attributes();
QString rect = ellipseProperties.namedItem(QStringLiteral("rect")).nodeValue();
QString br_str = ellipseProperties.namedItem(QStringLiteral("brushcolor")).nodeValue();
QString pen_str = ellipseProperties.namedItem(QStringLiteral("pencolor")).nodeValue();
double penwidth = ellipseProperties.namedItem(QStringLiteral("penwidth")).nodeValue().toDouble();
auto *ellipse = new MyEllipseItem();
ellipse->setRect(stringToRect(rect));
if (penwidth > 0) {
ellipse->setPen(QPen(QBrush(stringToColor(pen_str)), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
} else {
ellipse->setPen(Qt::NoPen);
}
if (!ellipseProperties.namedItem(QStringLiteral("gradient")).isNull()) {
// Gradient color
QString data = ellipseProperties.namedItem(QStringLiteral("gradient")).nodeValue();
ellipse->setData(TitleDocument::Gradient, data);
QLinearGradient gr = GradientWidget::gradientFromString(data, ellipse->rect().width(), ellipse->rect().height());
ellipse->setBrush(QBrush(gr));
} else {
ellipse->setBrush(QBrush(stringToColor(br_str)));
}
gitems.append(ellipse);
gitem = ellipse;
} else if (itemNode.attributes().namedItem(QStringLiteral("type")).nodeValue() == QLatin1String("QGraphicsPixmapItem")) {
QString url = itemNode.namedItem(QStringLiteral("content")).attributes().namedItem(QStringLiteral("url")).nodeValue();
QString base64 = itemNode.namedItem(QStringLiteral("content")).attributes().namedItem(QStringLiteral("base64")).nodeValue();
......
......@@ -72,6 +72,7 @@ int settingUp = 0;
const int IMAGEITEM = 7;
const int RECTITEM = 3;
const int TEXTITEM = 8;
const int ELLIPSEITEM = 4;
/*
const int NOEFFECT = 0;
......@@ -195,12 +196,12 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, QString projectTit
if (mlt_version_get_int() < 0x061900) {
typewriterBox->setEnabled(false);
auto *twinfo = new KMessageWidget(typewriterBox);
twinfo->setText(i18n("Typewriter requires MLT-6.26.0 or newer."));
twinfo->setMessageType(KMessageWidget::Warning);
twinfo->setCloseButtonVisible(false);
twinfo->setEnabled(true);
gridLayout_12->addWidget(twinfo, 3, 0, 1, 4, 0);
auto *twinfo = new KMessageWidget(typewriterBox);
twinfo->setText(i18n("Typewriter requires MLT-6.26.0 or newer."));
twinfo->setMessageType(KMessageWidget::Warning);
twinfo->setCloseButtonVisible(false);
twinfo->setEnabled(true);
gridLayout_12->addWidget(twinfo, 3, 0, 1, 4, 0);
}
connect(fontColorButton, &KColorButton::changed, this, &TitleWidget::slotUpdateText);
......@@ -438,6 +439,15 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, QString projectTit
m_buttonRect->setToolTip(i18n("Add Rectangle") + QLatin1Char(' ') + m_buttonRect->shortcut().toString());
connect(m_buttonRect, &QAction::triggered, this, &TitleWidget::slotRectTool);
m_buttonEllipse = m_toolbar->addAction(QIcon::fromTheme(QStringLiteral("draw-ellipse")), i18n("Add Ellipse"));
m_buttonEllipse->setCheckable(true);
m_buttonEllipse->setShortcut(Qt::ALT + Qt::Key_E);
m_buttonEllipse->setToolTip(i18n("Add Ellipse") + QLatin1Char(' ') + m_buttonEllipse->shortcut().toString());
connect(m_buttonEllipse, &QAction::triggered, this, &TitleWidget::slotEllipseTool);
if (mlt_version_get_int() < 0x061900) {
m_buttonEllipse->setVisible(false);
}
m_buttonImage = m_toolbar->addAction(QIcon::fromTheme(QStringLiteral("insert-image")), i18n("Add Image"));
m_buttonImage->setCheckable(false);
m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
......@@ -534,6 +544,7 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, QString projectTit
connect(m_scene, &GraphicsSceneRectMove::sceneZoom, this, &TitleWidget::slotZoom);
connect(m_scene, &GraphicsSceneRectMove::actionFinished, this, &TitleWidget::slotSelectTool);
connect(m_scene, &GraphicsSceneRectMove::newRect, this, &TitleWidget::slotNewRect);
connect(m_scene, &GraphicsSceneRectMove::newEllipse, this, &TitleWidget::slotNewEllipse);
connect(m_scene, &GraphicsSceneRectMove::newText, this, &TitleWidget::slotNewText);
connect(zoom_slider, &QAbstractSlider::valueChanged, this, &TitleWidget::slotUpdateZoom);
connect(zoom_spin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &TitleWidget::slotUpdateZoom);
......@@ -605,12 +616,12 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, QString projectTit
connect(btn_add, &QToolButton::clicked, this, &TitleWidget::slotPatternBtnAddClicked);
connect(btn_remove, &QToolButton::clicked, this, &TitleWidget::slotPatternBtnRemoveClicked);
connect(btn_removeAll, &QToolButton::clicked, this,
connect(btn_removeAll, &QToolButton::clicked, this,
[&] () {
m_patternsModel->removeAll();
btn_remove->setEnabled(false);
btn_removeAll->setEnabled(false);
});
m_patternsModel->removeAll();
btn_remove->setEnabled(false);
btn_removeAll->setEnabled(false);
});
scaleSlider->setRange(6, 16);
patternsList->setModel(m_patternsModel);
......@@ -643,6 +654,7 @@ TitleWidget::~TitleWidget()
m_scene->blockSignals(true);
delete m_buttonRect;
delete m_buttonEllipse;
delete m_buttonText;
delete m_buttonImage;
delete m_buttonCursor;
......@@ -793,6 +805,16 @@ void TitleWidget::slotRectTool()
graphicsView->setDragMode(QGraphicsView::NoDrag);
}
void TitleWidget::slotEllipseTool()
{
m_scene->setTool(TITLE_ELLIPSE);
showToolbars(TITLE_ELLIPSE);
checkButton(TITLE_ELLIPSE);
// Disable dragging mode, would make dragging a ellipse impossible otherwise ;)
graphicsView->setDragMode(QGraphicsView::NoDrag);
}
void TitleWidget::slotSelectTool()
{
m_scene->setTool(TITLE_SELECT);
......@@ -811,6 +833,9 @@ void TitleWidget::slotSelectTool()
case RECTITEM:
t = TITLE_RECTANGLE;
break;
case ELLIPSEITEM:
t = TITLE_ELLIPSE;
break;
case IMAGEITEM:
t = TITLE_IMAGE;
break;
......@@ -889,6 +914,7 @@ void TitleWidget::showToolbars(TITLETOOL toolType)
case TITLE_IMAGE:
toolbar_stack->setCurrentIndex(2);
break;
case TITLE_ELLIPSE:
case TITLE_RECTANGLE:
toolbar_stack->setCurrentIndex(1);
break;
......@@ -903,7 +929,7 @@ void TitleWidget::enableToolbars(TITLETOOL toolType)
{
// TITLETOOL is defined in effectstack/graphicsscenerectmove.h
bool enable = false;
if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) {
if (toolType == TITLE_RECTANGLE || toolType == TITLE_ELLIPSE || toolType == TITLE_IMAGE) {
enable = true;
}
value_w->setEnabled(enable);
......@@ -915,6 +941,7 @@ void TitleWidget::checkButton(TITLETOOL toolType)
bool bSelect = false;
bool bText = false;
bool bRect = false;
bool bEllipse = false;
bool bImage = false;
switch (toolType) {
......@@ -927,6 +954,9 @@ void TitleWidget::checkButton(TITLETOOL toolType)
case TITLE_RECTANGLE:
bRect = true;
break;
case TITLE_ELLIPSE:
bEllipse = true;
break;
case TITLE_IMAGE:
bImage = true;
break;
......@@ -937,6 +967,7 @@ void TitleWidget::checkButton(TITLETOOL toolType)
m_buttonCursor->setChecked(bSelect);
m_buttonText->setChecked(bText);
m_buttonRect->setChecked(bRect);
m_buttonEllipse->setChecked(bEllipse);
m_buttonImage->setChecked(bImage);
}
......@@ -945,30 +976,30 @@ void TitleWidget::displayBackgroundFrame()
QRectF r = m_frameBorder->sceneBoundingRect();
if (!displayBg->isChecked()) {
switch (KdenliveSettings::titlerbg()) {
case 0: {
QPixmap pattern(20, 20);
pattern.fill(Qt::gray);
QColor bgcolor(180, 180, 180);
QPainter p(&pattern);
p.fillRect(QRect(0, 0, 10, 10), bgcolor);
p.fillRect(QRect(10, 10, 20, 20), bgcolor);
p.end();
QBrush br(pattern);
QPixmap bg((int)(r.width() / 2), (int)(r.height() / 2));
QPainter p2(&bg);
p2.fillRect(bg.rect(), br);
p2.end();
m_frameImage->setPixmap(bg);
break;
}
default: {
QColor col = KdenliveSettings::titlerbg() == 1 ? Qt::black : Qt::white;
QPixmap bg((int)(r.width() / 2), (int)(r.height() / 2));
QPainter p2(&bg);
p2.fillRect(bg.rect(), col);
p2.end();
m_frameImage->setPixmap(bg);
}
case 0: {
QPixmap pattern(20, 20);
pattern.fill(Qt::gray);
QColor bgcolor(180, 180, 180);
QPainter p(&pattern);
p.fillRect(QRect(0, 0, 10, 10), bgcolor);
p.fillRect(QRect(10, 10, 20, 20), bgcolor);
p.end();
QBrush br(pattern);
QPixmap bg((int)(r.width() / 2), (int)(r.height() / 2));
QPainter p2(&bg);
p2.fillRect(bg.rect(), br);
p2.end();
m_frameImage->setPixmap(bg);
break;
}
default: {
QColor col = KdenliveSettings::titlerbg() == 1 ? Qt::black : Qt::white;
QPixmap bg((int)(r.width() / 2), (int)(r.height() / 2));
QPainter p2(&bg);
p2.fillRect(bg.rect(), col);
p2.end();
m_frameImage->setPixmap(bg);
}
}
emit updatePatternsBackgroundFrame();
} else {
......@@ -1077,6 +1108,35 @@ void TitleWidget::slotNewRect(QGraphicsRectItem *rect)
// graphicsView->setFocus();
}
void TitleWidget::slotNewEllipse(QGraphicsEllipseItem *ellipse)
{
updateAxisButtons(ellipse); // back to default
if (rectLineWidth->value() == 0) {
ellipse->setPen(Qt::NoPen);
} else {
QPen penf(rectFColor->color());
penf.setWidth(rectLineWidth->value());
penf.setJoinStyle(Qt::RoundJoin);
ellipse->setPen(penf);
}
if (plain_rect->isChecked()) {
ellipse->setBrush(QBrush(rectBColor->color()));
ellipse->setData(TitleDocument::Gradient, QVariant());
} else {
// gradient
QString gradientData = gradients_rect_combo->currentData().toString();
ellipse->setData(TitleDocument::Gradient, gradientData);
QLinearGradient gr = GradientWidget::gradientFromString(gradientData, ellipse->boundingRect().width(), ellipse->boundingRect().height());
ellipse->setBrush(QBrush(gr));
}
ellipse->setZValue(m_count++);
ellipse->setData(TitleDocument::ZoomFactor, 100);
prepareTools(ellipse);
// setCurrentItem(rect);
// graphicsView->setFocus();
}
void TitleWidget::slotNewText(MyTextItem *tt)
{
updateAxisButtons(tt); // back to default
......@@ -1311,6 +1371,23 @@ void TitleWidget::slotValueChanged(int type)
break;
}
} else if (l.at(k)->type() == ELLIPSEITEM) {
auto *ellipse = static_cast<QGraphicsEllipseItem *>(l.at(k));
switch (type) {
case ValueX:
updatePosition(l.at(k), val, l.at(k)->pos().y());
break;
case ValueY:
updatePosition(l.at(k), l.at(k)->pos().x(), val);
break;
case ValueWidth:
ellipse->setRect(QRect(0, 0, val, ellipse->rect().height()));
break;
case ValueHeight:
ellipse->setRect(QRect(0, 0, ellipse->rect().width(), val));
break;
}
} else if (l.at(k)->type() == IMAGEITEM) {
if (type == ValueX) {
......@@ -1404,7 +1481,7 @@ void TitleWidget::updateDimension(QGraphicsItem *i)
value_w->setValue(i->sceneBoundingRect().width());
value_h->setValue(i->sceneBoundingRect().height());
} else if (i->type() == RECTITEM) {
} else if (i->type() == RECTITEM || i->type() == ELLIPSEITEM) {
auto *r = static_cast<QGraphicsRectItem *>(i);
// qCDebug(KDENLIVE_LOG) << "Rect width is: " << r->rect().width() << ", was: " << value_w->value() << '\n';
value_w->setValue((int)r->rect().width());
......@@ -1464,6 +1541,24 @@ void TitleWidget::updateCoordinates(QGraphicsItem *i)
value_y->setValue((int)rec->pos().y());
}
} else if (i->type() == ELLIPSEITEM) {
auto *rec = static_cast<QGraphicsEllipseItem *>(i);
if (origin_x_left->isChecked()) {
// Origin (0 point) is at m_frameWidth
value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
} else {
// Origin is at 0 (default)
value_x->setValue((int)rec->pos().x());
}
if (origin_y_top->isChecked()) {
value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
} else {
value_y->setValue((int)rec->pos().y());
}
} else if (i->type() == IMAGEITEM) {
if (origin_x_left->isChecked()) {
......@@ -1561,6 +1656,26 @@ void TitleWidget::updatePosition(QGraphicsItem *i, int x, int y)
rec->setPos(posX, posY);
} else if (i->type() == ELLIPSEITEM) {
auto *rec = static_cast<QGraphicsEllipseItem *>(i);
int posX;
if (origin_x_left->isChecked()) {
posX = m_frameWidth - x - rec->rect().width();
} else {
posX = x;
}
int posY;
if (origin_y_top->isChecked()) {
posY = m_frameHeight - y - rec->rect().height();
} else {
posY = y;
}
rec->setPos(posX, posY);
} else if (i->type() == IMAGEITEM) {
int posX;
if (origin_x_left->isChecked()) {
......@@ -1824,6 +1939,27 @@ void TitleWidget::rectChanged()
QLinearGradient gr = GradientWidget::gradientFromString(gradientData, rec->boundingRect().width(), rec->boundingRect().height());
rec->setBrush(QBrush(gr));
}
} else if (i->type() == ELLIPSEITEM && (settingUp == 0)) {
auto *ellipse = static_cast<QGraphicsEllipseItem *>(i);
QColor f = rectFColor->color();
if (rectLineWidth->value() == 0) {
ellipse->setPen(Qt::NoPen);
} else {
QPen penf(f);
penf.setWidth(rectLineWidth->value());
penf.setJoinStyle(Qt::RoundJoin);
ellipse->setPen(penf);
}
if (plain_rect->isChecked()) {
ellipse->setBrush(QBrush(rectBColor->color()));
ellipse->setData(TitleDocument::Gradient, QVariant());
} else {
// gradient
QString gradientData = gradients_rect_combo->currentData().toString();
ellipse->setData(TitleDocument::Gradient, gradientData);
QLinearGradient gr = GradientWidget::gradientFromString(gradientData, ellipse->boundingRect().width(), ellipse->boundingRect().height());
ellipse->setBrush(QBrush(gr));
}
}
}
}
......@@ -2103,7 +2239,7 @@ QUrl TitleWidget::saveTitle(QUrl url)
}
}
if (embed_image && KMessageBox::questionYesNo(
this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::Yes) {
this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::Yes) {
embed_image = false;
}
if (!url.isValid()) {
......@@ -2765,6 +2901,11 @@ void TitleWidget::slotSelectRects()
selectItems(RECTITEM);
}
void TitleWidget::slotSelectEllipses()
{
selectItems(ELLIPSEITEM);