]> git.sesse.net Git - kdenlive/commitdiff
Worked on #846
authorSimon A. Eugster <simon.eu@gmail.com>
Thu, 11 Jun 2009 19:47:06 +0000 (19:47 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Thu, 11 Jun 2009 19:47:06 +0000 (19:47 +0000)
svn path=/trunk/kdenlive/; revision=3517

src/titlewidget.cpp
src/titlewidget.h
src/widgets/titlewidget_ui.ui

index e3d1f8251405bc17c9033068787b8267aa88aa71..9ef5a9007cea34a1cb0bf112e63391c1f7f13951 100644 (file)
@@ -92,6 +92,9 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
     connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
     connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
 
+       connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
+       connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
+
     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(slotAdjustSelectedItem()));
@@ -506,8 +509,7 @@ void TitleWidget::selectionChanged()
             buttonAlignNone->blockSignals(false);
             buttonAlignCenter->blockSignals(false);
 
-            value_x->setValue((int) i->pos().x());
-            value_y->setValue((int) i->pos().y());
+                       updateCoordinates(i);
             value_w->setValue((int) i->boundingRect().width());
             value_h->setValue((int) i->boundingRect().height());
             frame_properties->setEnabled(true);
@@ -531,8 +533,8 @@ void TitleWidget::selectionChanged()
             rectBColor->setColor(bcol);
             settingUp = false;
             rectLineWidth->setValue(rec->pen().width());
-            value_x->setValue((int) rec->pos().x());
-            value_y->setValue((int) rec->pos().y());
+                       
+                       updateCoordinates(rec);
             value_w->setValue((int) rec->rect().width());
             value_h->setValue((int) rec->rect().height());
             frame_properties->setEnabled(true);
@@ -561,16 +563,133 @@ void TitleWidget::slotAdjustSelectedItem()
         if (l.at(0)->type() == RECTITEM) {
             //rect item
             QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
-            rec->setPos(value_x->value(), value_y->value());
+                       updatePosition(rec);
             rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
         } else if (l.at(0)->type() == TEXTITEM) {
             //text item
-            QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(l.at(0));
-            rec->setPos(value_x->value(), value_y->value());
+            updatePosition(l.at(0));
         }
     }
 }
 
+void TitleWidget::updateCoordinates(QGraphicsItem *i) 
+{
+       value_x->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
+                       value_x->setValue((int) (rec->pos().x() + rec->boundingRect().width() - m_frameWidth)); 
+               } 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) (rec->pos().y() + rec->boundingRect().height() - m_frameHeight));
+               } 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) (rec->pos().x() + rec->rect().width() - m_frameWidth)); 
+               } else {
+                       // Origin is at 0 (default)
+                       value_x->setValue((int) rec->pos().x());
+               }
+               
+               if (origin_y_top->isChecked()) {
+                       value_y->setValue((int) (rec->pos().y() + rec->rect().height() - m_frameHeight));
+               } else {
+                       value_y->setValue((int) rec->pos().y());
+               }
+               
+               
+       }
+       
+       value_x->blockSignals(false);
+}
+
+void TitleWidget::updatePosition(QGraphicsItem *i) {
+       
+       if (i->type() == TEXTITEM) {
+               QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
+               
+               int posX = value_x->value();
+               if (origin_x_left->isChecked()) {
+                       /* Origin of the x axis is at m_frameWidth,
+                        * and distance to right border of the item is taken.
+                        * Add m_frameWidth, subtract object width 
+                        */
+                       posX += m_frameWidth - rec->boundingRect().width();
+               }
+               
+               int posY = value_y->value();
+               if (origin_y_top->isChecked()) {
+                       /* Same for y axis */
+                       posY += m_frameHeight - rec->boundingRect().height();
+               }
+               
+               rec->setPos(posX, posY);
+       } else if (i->type() == RECTITEM) {
+               
+               QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *> (i);
+               
+               int posX = value_x->value();
+               if (origin_x_left->isChecked()) {
+                       posX += m_frameWidth - rec->rect().width();
+               }
+               
+               int posY = value_y->value();
+               if (origin_y_top->isChecked()) {
+                       posY += m_frameHeight - rec->rect().height();
+               }
+               
+               rec->setPos(posX, posY);
+       }
+       
+}
+
+void TitleWidget::slotOriginXClicked()
+{
+       // Update the text displayed on the button.
+       if (origin_x_left->isChecked()) {
+               origin_x_left->setText(i18n("\u2212X"));
+       } else {
+               origin_x_left->setText(i18n("+X"));
+       }
+       
+       QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+       if (l.size() >= 1) {
+               updateCoordinates(l.at(0));
+       }
+}
+
+void TitleWidget::slotOriginYClicked()
+{
+       // Update the text displayed on the button.
+       if (origin_y_top->isChecked()) {
+               origin_y_top->setText(i18n("\u2212Y"));
+       } else {
+               origin_y_top->setText(i18n("+Y"));
+       }
+       
+       QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+       if (l.size() >= 1) {
+               updateCoordinates(l.at(0));
+       }
+}
+
 void TitleWidget::slotChangeBackground()
 {
     QColor color = kcolorbutton->color();
@@ -580,11 +699,18 @@ void TitleWidget::slotChangeBackground()
 
 void TitleWidget::textChanged()
 {
+       // TODO not yet working
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
-    if (l.size() == 1 && l.at(0)->type() == TEXTITEM && !l.at(0)->hasFocus()) {
-        //kDebug() << ktextedit->document()->toHtml();
-        //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
-    }
+       if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
+               if (origin_x_left->isChecked()) {
+                       updatePosition(l.at(0));
+               }
+               
+       }
+    //if (l.size() == 1 && l.at(0)->type() == TEXTITEM && !l.at(0)->hasFocus()) {
+    //    kDebug() << ktextedit->document()->toHtml();
+    //    ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
+    //}
 }
 
 void TitleWidget::slotUpdateText()
index fdf902c04af23491ace059af5b169a5c41ab37a6..da3b7a3c6a2bb5f8b35b7a18cb13084b1ee837e0 100644 (file)
@@ -95,6 +95,10 @@ private:
     void writeChoices();
     /** \brief Read the last stored choices into the dialog */
     void readChoices();
+       /** \brief Update the displayed X/Y coordinates */
+       void updateCoordinates(QGraphicsItem *i);
+       /** \brief Update the item's position */
+       void updatePosition(QGraphicsItem *i);
 
 public slots:
     void slotNewText(QGraphicsTextItem *tt);
@@ -116,17 +120,58 @@ public slots:
 
 private slots:
     void slotAdjustSelectedItem();
-    void slotUpdateZoom(int pos);
+       
+       /** 
+        * \brief Switches the origin of the x axis between left and right 
+        * border of the frame (offset from left/right frame border)
+        * \param originLeft Take left border?
+        * 
+        * Called when the origin of the x coorinate has been changed. The 
+        * x origin will either be at the left or at the right side of the frame.
+        * 
+        * When the origin of the x axis is at the left side, the user can 
+        * enter the distance between an element's left border and the left
+        * side of the frame.
+        * 
+        * When on the right, the distance from the right border of the 
+        * frame to the right border of the element can be entered. This 
+        * will result in negative values as long as the element's right 
+        * border is at the left of the frame's right border.
+        * 
+        * Default value is left.
+        * 
+        * |----l----->|#######|<-------r|              
+        * |           |---w-->|         |
+        * |           |#######|         |
+        * |                             |
+        * |----------m_frameWidth------>|
+        * |                             |
+        * 
+        * Left selected: Value = l
+        * Right selected: Value = m_frameWidth + r - w
+        * 
+        */
+       void slotOriginXClicked();
+       /** \brief Same as slotOriginYChanged, but for the Y axis; default is top. 
+        *  \param originTop Take top border? */
+       void slotOriginYClicked();
+       
     void slotZoom(bool up);
+    void slotUpdateZoom(int pos);
     void slotAdjustZoom();
     void slotZoomOneToOne();
+       
     void slotUpdateText();
+       
     void displayBackgroundFrame();
+       
     void setCurrentItem(QGraphicsItem *item);
+       
     void slotTextTool();
     void slotRectTool();
     void slotSelectTool();
     void slotImageTool();
+       
     /** \brief Called when accepted, stores the user selections for next time use */
     void slotAccepted();
 };
index 5e37104a953c1b1bdcdf4ecc7d82543ff493f766..970d8e7c2d22f69e5fba232dd5aa6e34d424576b 100644 (file)
       <item row="0" column="0">
        <layout class="QHBoxLayout" name="positionLayout">
         <item>
-         <widget class="QLabel" name="label_16">
+         <widget class="QPushButton" name="origin_x_left">
           <property name="text">
-           <string>X</string>
-          </property>
+           <string>+X</string>
+          </property>
+                 <property name="checkable">
+                  <bool>true</bool>
+                 </property>
+                 <property name="checked">
+                  <bool>false</bool>
+                 </property>
          </widget>
         </item>
         <item>
          <widget class="QSpinBox" name="value_x">
           <property name="minimum">
-           <number>-1000</number>
+           <number>-5000</number>
           </property>
           <property name="maximum">
            <number>5000</number>
          </widget>
         </item>
         <item>
-         <widget class="QLabel" name="label_17">
+         <widget class="QPushButton" name="origin_y_top">
           <property name="text">
-           <string>Y</string>
-          </property>
+           <string>+Y</string>
+          </property>
+                 <property name="checkable">
+                  <bool>true</bool>
+                 </property>
+                 <property name="checked">
+                  <bool>false</bool>
+                 </property>
          </widget>
         </item>
         <item>
          <widget class="QSpinBox" name="value_y">
           <property name="minimum">
-           <number>-1000</number>
+           <number>-5000</number>
           </property>
           <property name="maximum">
            <number>5000</number>