From: Jean-Baptiste Mardelle Date: Mon, 4 May 2009 22:15:09 +0000 (+0000) Subject: Restore zoom & rotation of objects: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=a25ce8f8a435d7d7df06df7f074c5f2fef53d8c8;p=kdenlive Restore zoom & rotation of objects: http://www.kdenlive.org/mantis/view.php?id=810 svn path=/trunk/kdenlive/; revision=3358 --- diff --git a/src/titledocument.cpp b/src/titledocument.cpp index ad2cc5b7..4b6ab4e4 100644 --- a/src/titledocument.cpp +++ b/src/titledocument.cpp @@ -302,7 +302,7 @@ QRectF TitleDocument::stringToRect(const QString & s) QStringList l = s.split(','); if (l.size() < 4) return QRectF(); - return QRectF(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble()).normalized(); + return QRectF(l.at(0).toDouble(), l.at(1).toDouble(), l.at(2).toDouble(), l.at(3).toDouble()).normalized(); } QColor TitleDocument::stringToColor(const QString & s) @@ -310,7 +310,7 @@ QColor TitleDocument::stringToColor(const QString & s) QStringList l = s.split(','); if (l.size() < 4) return QColor(); - return QColor(l[0].toInt(), l[1].toInt(), l[2].toInt(), l[3].toInt());; + return QColor(l.at(0).toInt(), l.at(1).toInt(), l.at(2).toInt(), l.at(3).toInt());; } QTransform TitleDocument::stringToTransform(const QString& s) { @@ -318,8 +318,8 @@ QTransform TitleDocument::stringToTransform(const QString& s) if (l.size() < 9) return QTransform(); return QTransform( - l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), - l[3].toDouble(), l[4].toDouble(), l[5].toDouble(), - l[6].toDouble(), l[7].toDouble(), l[8].toDouble() + l.at(0).toDouble(), l.at(1).toDouble(), l.at(2).toDouble(), + l.at(3).toDouble(), l.at(4).toDouble(), l.at(5).toDouble(), + l.at(6).toDouble(), l.at(7).toDouble(), l.at(8).toDouble() ); } diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index a227f170..d8876bae 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -33,6 +33,10 @@ int settingUp = false; +const int IMAGEITEM = 7; +const int RECTITEM = 3; +const int TEXTITEM = 8; + TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget *parent) : QDialog(parent), Ui::TitleWidget_UI(), @@ -436,12 +440,13 @@ void TitleWidget::selectionChanged() value_y->blockSignals(true); value_w->blockSignals(true); value_h->blockSignals(true); - //kDebug() << "//////// SELECTION CHANGED; ITEMS: " << l.size(); + itemzoom->blockSignals(true); + itemrotate->blockSignals(true); if (l.size() == 1) { - if ((l[0])->type() == 8) { + if (l.at(0)->type() == TEXTITEM) { rect_properties->setHidden(true); text_properties->setHidden(false); - QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]); + QGraphicsTextItem* i = static_cast (l.at(0)); //if (l[0]->hasFocus()) //ktextedit->setHtml(i->toHtml()); toolBox->setCurrentIndex(0); @@ -480,11 +485,11 @@ void TitleWidget::selectionChanged() frame_properties->setEnabled(true); value_w->setEnabled(false); value_h->setEnabled(false); - } else if ((l[0])->type() == 3) { + } else if ((l.at(0))->type() == RECTITEM) { rect_properties->setHidden(false); text_properties->setHidden(true); settingUp = true; - QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]); + QGraphicsRectItem *rec = static_cast (l.at(0)); toolBox->setCurrentIndex(0); //toolBox->setItemEnabled(3, true); rectFAlpha->setValue(rec->pen().color().alpha()); @@ -509,13 +514,15 @@ void TitleWidget::selectionChanged() //toolBox->setCurrentIndex(0); frame_properties->setEnabled(false); } - zValue->setValue((int)l[0]->zValue()); - itemzoom->setValue((int)(m_transformations[l[0]].scalex * 100)); - itemrotate->setValue((int)(m_transformations[l[0]].rotate)); + zValue->setValue((int)l.at(0)->zValue()); + itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5)); + itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate)); value_x->blockSignals(false); value_y->blockSignals(false); value_w->blockSignals(false); value_h->blockSignals(false); + itemzoom->blockSignals(false); + itemrotate->blockSignals(false); } else frame_properties->setEnabled(false); } @@ -523,14 +530,14 @@ void TitleWidget::slotAdjustSelectedItem() { QList l = graphicsView->scene()->selectedItems(); if (l.size() >= 1) { - if (l[0]->type() == 3) { + if (l.at(0)->type() == RECTITEM) { //rect item - QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]); + QGraphicsRectItem *rec = static_cast (l.at(0)); rec->setPos(value_x->value(), value_y->value()); rec->setRect(QRect(0, 0, value_w->value(), value_h->value())); - } else if (l[0]->type() == 8) { + } else if (l.at(0)->type() == TEXTITEM) { //text item - QGraphicsTextItem *rec = ((QGraphicsTextItem*)l[0]); + QGraphicsTextItem *rec = static_cast (l.at(0)); rec->setPos(value_x->value(), value_y->value()); } } @@ -546,7 +553,7 @@ void TitleWidget::slotChangeBackground() void TitleWidget::textChanged() { QList l = graphicsView->scene()->selectedItems(); - if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) { + if (l.size() == 1 && l.at(0)->type() == TEXTITEM && !l.at(0)->hasFocus()) { //kDebug() << ktextedit->document()->toHtml(); //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml()); } @@ -564,8 +571,8 @@ void TitleWidget::slotUpdateText() QGraphicsTextItem* item = NULL; QList l = graphicsView->scene()->selectedItems(); - if (l.size() == 1 && (l[0])->type() == 8) { - item = (QGraphicsTextItem*)l[0]; + if (l.size() == 1 && l.at(0)->type() == TEXTITEM) { + item = static_cast (l.at(0)); } if (!item) return; //if (item->textCursor().selection ().isEmpty()) @@ -591,8 +598,8 @@ void TitleWidget::slotUpdateText() void TitleWidget::rectChanged() { QList l = graphicsView->scene()->selectedItems(); - if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) { - QGraphicsRectItem *rec = (QGraphicsRectItem*)l[0]; + if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) { + QGraphicsRectItem *rec = static_cast(l.at(0)); QColor f = rectFColor->color(); f.setAlpha(rectFAlpha->value()); QPen penf(f); @@ -607,7 +614,7 @@ void TitleWidget::rectChanged() void TitleWidget::fontBold() { QList l = graphicsView->scene()->selectedItems(); - if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) { + if (l.size() == 1 && l.at(0)->type() == TEXTITEM && !l.at(0)->hasFocus()) { //ktextedit->document()->setTextOption(); } } @@ -616,14 +623,14 @@ void TitleWidget::itemScaled(int val) { QList l = graphicsView->scene()->selectedItems(); if (l.size() == 1) { - Transform x = m_transformations[l[0]]; + Transform x = m_transformations.value(l.at(0)); x.scalex = (double)val / 100.0; x.scaley = (double)val / 100.0; QTransform qtrans; qtrans.scale(x.scalex, x.scaley); qtrans.rotate(x.rotate); l[0]->setTransform(qtrans); - m_transformations[l[0]] = x; + m_transformations[l.at(0)] = x; } } @@ -631,13 +638,13 @@ void TitleWidget::itemRotate(int val) { QList l = graphicsView->scene()->selectedItems(); if (l.size() == 1) { - Transform x = m_transformations[l[0]]; + Transform x = m_transformations[l.at(0)]; x.rotate = (double)val; QTransform qtrans; qtrans.scale(x.scalex, x.scaley); qtrans.rotate(x.rotate); l[0]->setTransform(qtrans); - m_transformations[l[0]] = x; + m_transformations[l.at(0)] = x; } } @@ -645,11 +652,11 @@ void TitleWidget::itemHCenter() { QList l = graphicsView->scene()->selectedItems(); if (l.size() == 1) { - QGraphicsItem *item = l[0]; + QGraphicsItem *item = l.at(0); QRectF br; - if (item->type() == 3) { + if (item->type() == RECTITEM) { br = ((QGraphicsRectItem*)item)->rect(); - } else br = item->boundingRect(); + } else br = item->sceneBoundingRect(); int width = (int) br.width(); int newPos = (int)((m_frameWidth - width) / 2); item->setPos(newPos, item->pos().y()); @@ -660,11 +667,11 @@ void TitleWidget::itemVCenter() { QList l = graphicsView->scene()->selectedItems(); if (l.size() == 1) { - QGraphicsItem *item = l[0]; + QGraphicsItem *item = l.at(0); QRectF br; - if (item->type() == 3) { + if (item->type() == RECTITEM) { br = ((QGraphicsRectItem*)item)->rect(); - } else br = item->boundingRect(); + } else br = item->sceneBoundingRect(); int height = (int) br.height(); int newPos = (int)((m_frameHeight - height) / 2); item->setPos(item->pos().x(), newPos); @@ -721,6 +728,17 @@ QDomDocument TitleWidget::xml() void TitleWidget::setXml(QDomDocument doc) { m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport); + m_transformations.clear(); + QList items = graphicsView->scene()->items(); + const double PI = 4.0 * atan(1.0); + for (int i = 0; i < items.count(); i++) { + QTransform t = items.at(i)->transform(); + Transform x; + x.scalex = t.m11(); + x.scaley = t.m22(); + x.rotate = 180. / PI * atan2(-t.m21(), t.m11()); + m_transformations[items.at(i)] = x; + } // mbd: Update the GUI color selectors to match the stuff from the loaded document QColor background_color = m_titledocument.getBackgroundColor(); horizontalSlider->blockSignals(true);