+/** \brief Updates width/height int the text fields, regarding transformation matrix */
+void TitleWidget::updateDimension(QGraphicsItem *i)
+{
+ value_w->blockSignals(true);
+ value_h->blockSignals(true);
+
+
+ if (i->type() == IMAGEITEM) {
+ // Get multipliers for rotation/scaling
+
+ /*Transform t = m_transformations.value(i);
+ QRectF r = i->boundingRect();
+ int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
+ + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
+ int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
+ + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
+
+ value_w->setValue(i->sceneBoundingRect().width());
+ value_h->setValue(i->sceneBoundingRect().height());
+ } else if (i->type() == RECTITEM) {
+ QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
+ value_w->setValue((int) r->rect().width());
+ value_h->setValue((int) r->rect().height());
+ } else if (i->type() == TEXTITEM) {
+ QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
+ value_w->setValue((int) t->boundingRect().width());
+ value_h->setValue((int) t->boundingRect().height());
+ }
+
+ value_w->blockSignals(false);
+ value_h->blockSignals(false);
+}
+
+/** \brief Updates the coordinates in the text fields from the item */
+void TitleWidget::updateCoordinates(QGraphicsItem *i)
+{
+ // Block signals emitted by this method
+ value_x->blockSignals(true);
+ value_y->blockSignals(true);
+
+ if (i->type() == TEXTITEM) {
+
+ QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
+
+ // Set the correct x coordinate value
+ if (origin_x_left->isChecked()) {
+ // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
+ value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
+ } else {
+ // Origin is at 0 (default)
+ value_x->setValue((int) rec->pos().x());
+ }
+
+ // Same for y
+ if (origin_y_top->isChecked()) {
+ value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
+ } else {
+ value_y->setValue((int) rec->pos().y());
+ }
+
+ } else if (i->type() == RECTITEM) {
+
+ QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(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()) {
+ value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
+ } else {
+ value_x->setValue((int) i->pos().x());
+ }
+
+ if (origin_y_top->isChecked()) {
+ value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
+ } else {
+ value_y->setValue((int) i->pos().y());
+ }
+
+ }
+
+ // Stop blocking signals now
+ value_x->blockSignals(false);
+ 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)
+{
+ if (i->type() == TEXTITEM) {
+ QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
+
+ int posX;
+ if (origin_x_left->isChecked()) {
+ /* Origin of the x axis is at m_frameWidth,
+ * and distance from right border of the item to the right
+ * border of the frame is taken.
+ * See comment to slotOriginXClicked().
+ */
+ posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
+ } else {
+ posX = value_x->value();
+ }
+
+ int posY;
+ if (origin_y_top->isChecked()) {
+ /* Same for y axis */
+ posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
+ } else {
+ posY = value_y->value();
+ }
+
+ rec->setPos(posX, posY);
+
+ } else if (i->type() == RECTITEM) {
+
+ QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
+
+ int posX;
+ if (origin_x_left->isChecked()) {
+ posX = m_frameWidth - value_x->value() - rec->rect().width();
+ } else {
+ posX = value_x->value();
+ }
+
+ int posY;
+ if (origin_y_top->isChecked()) {
+ posY = m_frameHeight - value_y->value() - rec->rect().height();
+ } else {
+ posY = value_y->value();
+ }
+
+ rec->setPos(posX, posY);
+
+ } else if (i->type() == IMAGEITEM) {
+ int posX;
+ if (origin_x_left->isChecked()) {
+ // Use the sceneBoundingRect because this also regards transformations like zoom
+ posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
+ } else {
+ posX = value_x->value();
+ }
+
+ int posY;
+ if (origin_y_top->isChecked()) {
+ posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
+ } else {
+ posY = value_y->value();
+ }
+
+ i->setPos(posX, posY);
+
+ }
+
+}
+
+void TitleWidget::updateTextOriginX()
+{
+ if (origin_x_left->isChecked()) {
+ origin_x_left->setText(i18n("\u2212X"));
+ } else {
+ origin_x_left->setText(i18n("+X"));
+ }
+}
+
+void TitleWidget::slotOriginXClicked()
+{
+ // Update the text displayed on the button.
+ updateTextOriginX();
+
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() >= 1) {
+ updateCoordinates(l.at(0));
+
+ // Remember x axis setting
+ l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
+ TitleDocument::AxisInverted : TitleDocument::AxisDefault);
+ }
+ graphicsView->setFocus();
+}
+
+void TitleWidget::updateTextOriginY()
+{
+ if (origin_y_top->isChecked()) {
+ origin_y_top->setText(i18n("\u2212Y"));
+ } else {
+ origin_y_top->setText(i18n("+Y"));
+ }
+}
+
+void TitleWidget::slotOriginYClicked()
+{
+ // Update the text displayed on the button.
+ updateTextOriginY();
+
+ QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+ if (l.size() >= 1) {
+ updateCoordinates(l.at(0));
+
+ l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
+ TitleDocument::AxisInverted : TitleDocument::AxisDefault);
+
+ }
+ graphicsView->setFocus();
+}
+
+void TitleWidget::updateAxisButtons(QGraphicsItem *i)
+{
+ int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
+ int yAxis = i->data(TitleDocument::OriginYTop).toInt();
+ origin_x_left->blockSignals(true);
+ origin_y_top->blockSignals(true);
+
+ if (xAxis == TitleDocument::AxisInverted) {
+ origin_x_left->setChecked(true);
+ } else {
+ origin_x_left->setChecked(false);
+ }
+ updateTextOriginX();
+
+ if (yAxis == TitleDocument::AxisInverted) {
+ origin_y_top->setChecked(true);
+ } else {
+ origin_y_top->setChecked(false);
+ }
+ updateTextOriginY();
+
+ origin_x_left->blockSignals(false);
+ origin_y_top->blockSignals(false);
+}
+
+void TitleWidget::slotChangeBackground()
+{