Commit 43f4e060 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Titler: remember and restore last used text alignment.

CCBUG: 413572
parent 37dfd901
Pipeline #152964 passed with stage
in 6 minutes and 58 seconds
......@@ -1223,6 +1223,10 @@
<label>Show titler background.</label>
<default>false</default>
</entry>
<entry name="titlerAlign" type="Int">
<label>Default text align for titler.</label>
<default>0</default>
</entry>
</group>
<group name="speech">
<entry name="vosk_folder_path" type="String">
......
......@@ -8,6 +8,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "graphicsscenerectmove.h"
#include "titler/gradientwidget.h"
#include "titler/titledocument.h"
#include "kdenlivesettings.h"
#include "kdenlive_debug.h"
#include <QApplication>
......@@ -52,7 +53,7 @@ void MyQGraphicsEffect::draw(QPainter *painter)
MyTextItem::MyTextItem(const QString &txt, QGraphicsItem *parent)
: QGraphicsTextItem(txt, parent)
, m_alignment(qApp->isLeftToRight() ? Qt::AlignRight : Qt::AlignLeft)
, m_alignment(QFlags<Qt::AlignmentFlag>())
{
//Disabled because cache makes text cursor invisible and borders ugly
//setCacheMode(QGraphicsItem::ItemCoordinateCache);
......@@ -859,6 +860,7 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent *e)
textItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
textItem->setFocus(Qt::MouseFocusReason);
textItem->setAlignment(QFlags<Qt::AlignmentFlag>(KdenliveSettings::titlerAlign()));
emit newText(textItem);
m_selectedItem = textItem;
m_selectedItem->setSelected(true);
......
......@@ -37,7 +37,7 @@ class MyTextItem : public QGraphicsTextItem
{
Q_OBJECT
public:
MyTextItem(const QString &, QGraphicsItem *parent = nullptr);
MyTextItem(const QString& txt, QGraphicsItem* parent = nullptr);
void setAlignment(Qt::Alignment alignment);
/** @brief returns an extended bounding containing shadow */
QRectF boundingRect() const override;
......
......@@ -112,10 +112,14 @@ TitleWidget::TitleWidget(const QUrl &url, QString projectTitlePath, Monitor *mon
colorGroup->addButton(gradient_color);
colorGroup->addButton(plain_color);
auto *alignGroup = new QButtonGroup(this);
alignGroup->addButton(buttonAlignLeft);
alignGroup->addButton(buttonAlignCenter);
alignGroup->addButton(buttonAlignRight);
m_textAlignGroup = new QButtonGroup(this);
m_textAlignGroup->addButton(buttonAlignLeft, 0);
m_textAlignGroup->addButton(buttonAlignCenter, 1);
m_textAlignGroup->addButton(buttonAlignRight, 2);
QAbstractButton *selectedButton = m_textAlignGroup->button(KdenliveSettings::titlerAlign());
if (selectedButton) {
selectedButton->setChecked(true);
}
textOutline->setMinimum(0);
textOutline->setMaximum(200);
......@@ -235,9 +239,10 @@ TitleWidget::TitleWidget(const QUrl &url, QString projectTitlePath, Monitor *mon
connect(buttonRealSize, &QAbstractButton::clicked, this, &TitleWidget::slotZoomOneToOne);
connect(buttonItalic, &QAbstractButton::clicked, this, &TitleWidget::slotUpdateText);
connect(buttonUnder, &QAbstractButton::clicked, this, &TitleWidget::slotUpdateText);
connect(buttonAlignLeft, &QAbstractButton::clicked, this, &TitleWidget::slotUpdateText);
connect(buttonAlignRight, &QAbstractButton::clicked, this, &TitleWidget::slotUpdateText);
connect(buttonAlignCenter, &QAbstractButton::clicked, this, &TitleWidget::slotUpdateText);
connect(m_textAlignGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked), this, [this]() {
KdenliveSettings::setTitlerAlign(m_textAlignGroup->checkedId());
slotUpdateText();
});
connect(edit_gradient, &QAbstractButton::clicked, this, &TitleWidget::slotEditGradient);
connect(edit_rect_gradient, &QAbstractButton::clicked, this, &TitleWidget::slotEditGradient);
connect(preserveAspectRatio, static_cast<void (QCheckBox::*)(int)>(&QCheckBox::stateChanged), this, [&] () {
......@@ -273,12 +278,6 @@ TitleWidget::TitleWidget(const QUrl &url, QString projectTitlePath, Monitor *mon
buttonAlignLeft->setIconSize(iconSize);
buttonAlignRight->setIconSize(iconSize);
if (qApp->isLeftToRight()) {
buttonAlignRight->setChecked(true);
} else {
buttonAlignLeft->setChecked(true);
}
m_unicodeAction = new QAction(QIcon::fromTheme(QStringLiteral("kdenlive-insert-unicode")), QString(), this);
m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
m_unicodeAction->setToolTip(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
......@@ -3006,8 +3005,13 @@ void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
buttonAlignCenter->setChecked(true);
} else if (i->alignment() == Qt::AlignRight) {
buttonAlignRight->setChecked(true);
} else {
} else if (i->alignment() == Qt::AlignLeft) {
buttonAlignLeft->setChecked(true);
} else {
QAbstractButton *selectedButton = m_textAlignGroup->button(KdenliveSettings::titlerAlign());
if (selectedButton) {
selectedButton->setChecked(true);
}
}
QStringList sInfo = i->shadowInfo();
......
......@@ -112,6 +112,7 @@ private:
QGraphicsRectItem *m_frameBorder;
QGraphicsRectItem *m_frameBackground;
QGraphicsPixmapItem *m_frameImage;
QButtonGroup *m_textAlignGroup;
int m_frameWidth;
int m_frameHeight;
int m_count;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment