Some love for the tiler: allow white/black background instead of checkered texture

Align object buttons now cycle between safe zone and frame border
parent 3af87af2
...@@ -498,6 +498,12 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, QString projectTit ...@@ -498,6 +498,12 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, QString projectTit
displayBackgroundFrame(); displayBackgroundFrame();
graphicsView->scene()->addItem(m_frameImage); graphicsView->scene()->addItem(m_frameImage);
bgBox->setCurrentIndex(KdenliveSettings::titlerbg());
connect(bgBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [&] (int ix) {
KdenliveSettings::setTitlerbg(ix);
displayBackgroundFrame();
});
connect(m_scene, &QGraphicsScene::selectionChanged, this, &TitleWidget::selectionChanged); connect(m_scene, &QGraphicsScene::selectionChanged, this, &TitleWidget::selectionChanged);
connect(m_scene, &GraphicsSceneRectMove::itemMoved, this, &TitleWidget::selectionChanged); connect(m_scene, &GraphicsSceneRectMove::itemMoved, this, &TitleWidget::selectionChanged);
connect(m_scene, &GraphicsSceneRectMove::sceneZoom, this, &TitleWidget::slotZoom); connect(m_scene, &GraphicsSceneRectMove::sceneZoom, this, &TitleWidget::slotZoom);
...@@ -854,19 +860,32 @@ void TitleWidget::displayBackgroundFrame() ...@@ -854,19 +860,32 @@ void TitleWidget::displayBackgroundFrame()
{ {
QRectF r = m_frameBorder->sceneBoundingRect(); QRectF r = m_frameBorder->sceneBoundingRect();
if (!displayBg->isChecked()) { if (!displayBg->isChecked()) {
QPixmap pattern(20, 20); switch (KdenliveSettings::titlerbg()) {
pattern.fill(Qt::gray); case 0: {
QColor bgcolor(180, 180, 180); QPixmap pattern(20, 20);
QPainter p(&pattern); pattern.fill(Qt::gray);
p.fillRect(QRect(0, 0, 10, 10), bgcolor); QColor bgcolor(180, 180, 180);
p.fillRect(QRect(10, 10, 20, 20), bgcolor); QPainter p(&pattern);
p.end(); p.fillRect(QRect(0, 0, 10, 10), bgcolor);
QBrush br(pattern); p.fillRect(QRect(10, 10, 20, 20), bgcolor);
QPixmap bg((int)(r.width() / 2), (int)(r.height() / 2)); p.end();
QPainter p2(&bg); QBrush br(pattern);
p2.fillRect(bg.rect(), br); QPixmap bg((int)(r.width() / 2), (int)(r.height() / 2));
p2.end(); QPainter p2(&bg);
m_frameImage->setPixmap(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);
}
}
} else { } else {
emit requestBackgroundFrame(m_clipId, true); emit requestBackgroundFrame(m_clipId, true);
} }
...@@ -1813,13 +1832,25 @@ void TitleWidget::itemTop() ...@@ -1813,13 +1832,25 @@ void TitleWidget::itemTop()
{ {
QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems(); QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
if (l.size() == 1) { if (l.size() == 1) {
QList <double> margins {m_frameHeight * 0.05, m_frameHeight * 0.1};
QGraphicsItem *item = l.at(0); QGraphicsItem *item = l.at(0);
QRectF br = item->sceneBoundingRect(); QRectF br = item->sceneBoundingRect();
double diff; double diff;
if (br.top() > 0) { if (br.top() < 0.) {
diff = -br.top(); // align with big margin
diff = margins.at(1) - br.top();
} else if (qFuzzyIsNull(br.top())) {
// align right with frame border
diff = - br.bottom();
} else if (br.top() <= margins.at(0)) {
// align with 0
diff = - br.top();
} else if (br.top() <= margins.at(1)) {
// align with small margin
diff = margins.at(0) - br.top();
} else { } else {
diff = -br.bottom(); // align with big margin
diff = margins.at(1) - br.top();
} }
item->moveBy(0, diff); item->moveBy(0, diff);
updateCoordinates(item); updateCoordinates(item);
...@@ -1830,13 +1861,25 @@ void TitleWidget::itemBottom() ...@@ -1830,13 +1861,25 @@ void TitleWidget::itemBottom()
{ {
QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems(); QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
if (l.size() == 1) { if (l.size() == 1) {
QList <double> margins {m_frameHeight * 0.9, m_frameHeight* 0.95};
QGraphicsItem *item = l.at(0); QGraphicsItem *item = l.at(0);
QRectF br = item->sceneBoundingRect(); QRectF br = item->sceneBoundingRect();
double diff; double diff;
if (br.bottom() > m_frameHeight) { if (br.bottom() < margins.at(0)) {
// align with small margin
diff = margins.at(0) - br.bottom();
} else if (br.bottom() < margins.at(1)) {
// align big margin
diff = margins.at(1) - br.bottom();
} else if (br.bottom() < m_frameHeight) {
// align with frame
diff = m_frameHeight - br.bottom();
} else if (br.top() < m_frameHeight) {
// align left with frame
diff = m_frameHeight - br.top(); diff = m_frameHeight - br.top();
} else { } else {
diff = m_frameHeight - br.bottom(); // align with big margin
diff = margins.at(0) - br.bottom();
} }
item->moveBy(0, diff); item->moveBy(0, diff);
updateCoordinates(item); updateCoordinates(item);
...@@ -1847,13 +1890,25 @@ void TitleWidget::itemLeft() ...@@ -1847,13 +1890,25 @@ void TitleWidget::itemLeft()
{ {
QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems(); QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
if (l.size() == 1) { if (l.size() == 1) {
QList <double> margins {m_frameWidth * 0.05, m_frameWidth * 0.1};
QGraphicsItem *item = l.at(0); QGraphicsItem *item = l.at(0);
QRectF br = item->sceneBoundingRect(); QRectF br = item->sceneBoundingRect();
double diff; double diff;
if (br.left() > 0) { if (br.left() < 0.) {
diff = -br.left(); // align with big margin
diff = margins.at(1) - br.left();
} else if (qFuzzyIsNull(br.left())) {
// align right with frame border
diff = - br.right();
} else if (br.left() <= margins.at(0)) {
// align with 0
diff = - br.left();
} else if (br.left() <= margins.at(1)) {
// align with small margin
diff = margins.at(0) - br.left();
} else { } else {
diff = -br.right(); // align with big margin
diff = margins.at(1) - br.left();
} }
item->moveBy(diff, 0); item->moveBy(diff, 0);
updateCoordinates(item); updateCoordinates(item);
...@@ -1864,13 +1919,25 @@ void TitleWidget::itemRight() ...@@ -1864,13 +1919,25 @@ void TitleWidget::itemRight()
{ {
QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems(); QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
if (l.size() == 1) { if (l.size() == 1) {
QList <double> margins {m_frameWidth * 0.9, m_frameWidth * 0.95};
QGraphicsItem *item = l.at(0); QGraphicsItem *item = l.at(0);
QRectF br = item->sceneBoundingRect(); QRectF br = item->sceneBoundingRect();
double diff; double diff;
if (br.right() < m_frameWidth) { if (br.right() < margins.at(0)) {
// align with small margin
diff = margins.at(0) - br.right();
} else if (br.right() < margins.at(1)) {
// align big margin
diff = margins.at(1) - br.right();
} else if (br.right() < m_frameWidth) {
// align with frame
diff = m_frameWidth - br.right(); diff = m_frameWidth - br.right();
} else { } else if (br.left() < m_frameWidth) {
// align left with frame
diff = m_frameWidth - br.left(); diff = m_frameWidth - br.left();
} else {
// align with big margin
diff = margins.at(0) - br.right();
} }
item->moveBy(diff, 0); item->moveBy(diff, 0);
updateCoordinates(item); updateCoordinates(item);
......
...@@ -272,6 +272,25 @@ ...@@ -272,6 +272,25 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QComboBox" name="bgBox">
<item>
<property name="text">
<string>Checkered</string>
</property>
</item>
<item>
<property name="text">
<string>Black</string>
</property>
</item>
<item>
<property name="text">
<string>White</string>
</property>
</item>
</widget>
</item>
<item> <item>
<widget class="Line" name="line_6"> <widget class="Line" name="line_6">
<property name="orientation"> <property name="orientation">
......
Markdown is supported
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