#include "titlewidget.h"
#include "kdenlivesettings.h"
+#include <cmath>
+#include <iostream>
+
#include <KDebug>
#include <KGlobalSettings>
#include <KFileDialog>
connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
+ connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(ValueWidth, int)));
connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
+ connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(ValueHeight, int)));
connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
break;
case TITLE_IMAGE:
bFrame = true;
+ bValue_w = true;
+ bValue_h = true;
break;
default:
break;
}
}
+void TitleWidget::slotValueChanged(ValueType type, int val)
+{
+ std::cerr << "v";
+ QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
+ if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
+ std::cerr << "i";
+ QGraphicsItem *i = l.at(0);
+ Transform t = m_transformations.value(i);
+
+ // Ratio width:height
+ double phi = (double) i->boundingRect().width() / i->boundingRect().height();
+ double alpha = (double) t.rotate / 180.0 * M_PI;
+
+ // New length
+ double length = val;
+
+ // Scaling factor
+ double scale = 1;
+
+ switch (type) {
+ case ValueWidth:
+ // Add 0.5 because otherwise incrementing by 1 might have no effect
+ length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
+ scale = length / i->boundingRect().width();
+ std::cerr << "w";
+ break;
+ case ValueHeight:
+ length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
+ scale = length / i->boundingRect().height();
+ break;
+ }
+
+ t.scalex = scale;
+ t.scaley = scale;
+ QTransform qtrans;
+ qtrans.scale(scale, scale);
+ qtrans.rotate(t.rotate);
+ i->setTransform(qtrans);
+ m_transformations[i] = t;
+
+ updateDimension(i);
+ updateRotZoom(i);
+ }
+}
+
/** \brief Updates position/size of the selected item when a value
* of an item (coordinates, size) has changed */
void TitleWidget::slotAdjustSelectedItem()
/** \brief Updates width/height int the text fields, regarding transformation matrix */
void TitleWidget::updateDimension(QGraphicsItem *i)
{
- bool blockW = !value_w->signalsBlocked();
- bool blockH = !value_h->signalsBlocked();
-
- if (blockW) value_w->blockSignals(true);
- if (blockH) value_h->blockSignals(true);
+ value_w->blockSignals(true);
+ value_h->blockSignals(true);
if (i->type() == IMAGEITEM) {
value_h->setValue((int) t->boundingRect().height());
}
- if (blockW) value_w->blockSignals(false);
- if (blockH) value_h->blockSignals(false);
+ value_w->blockSignals(false);
+ value_h->blockSignals(false);
}
/** \brief Updates the coordinates in the text fields from the item */
value_y->blockSignals(false);
}
+void TitleWidget::updateRotZoom(QGraphicsItem *i)
+{
+ itemzoom->blockSignals(true);
+ itemrotate->blockSignals(false);
+
+ Transform t = m_transformations.value(i);
+ itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
+ itemrotate->setValue((int)(t.rotate));
+
+ itemzoom->blockSignals(false);
+ itemrotate->blockSignals(false);
+}
+
/** \brief Updates the position of an item by reading coordinates from the text fields */
void TitleWidget::updatePosition(QGraphicsItem *i)
{
UnicodeDialog *m_unicodeDialog;
/** project path for storing title clips */
QString m_projectTitlePath;
+
+ enum ValueType { ValueWidth, ValueHeight };
+
/** \brief Store the current choices of font, background and rect values */
void writeChoices();
/** \brief Read the last stored choices into the dialog */
void readChoices();
- /** \brief Update the displayed X/Y coordinates */
+ /** \brief Update the displayed X/Y coordinate values */
void updateCoordinates(QGraphicsItem *i);
+ /** \brief Update displayed width/height values */
void updateDimension(QGraphicsItem *i);
+ /** \brief Update displayed rotation/zoom values */
+ void updateRotZoom(QGraphicsItem *i);
+
/** \brief Update the item's position */
void updatePosition(QGraphicsItem *i);
/** \brief Update coorinates of text fields if necessary and text has changed */
void slotChanged();
+ void slotValueChanged(ValueType type, int val);
+
void slotZoom(bool up);
void slotUpdateZoom(int pos);
void slotAdjustZoom();