]> git.sesse.net Git - kdenlive/commitdiff
Images and SVG can now be added in titles through add image...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 6 Apr 2008 18:25:36 +0000 (18:25 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 6 Apr 2008 18:25:36 +0000 (18:25 +0000)
svn path=/branches/KDE4/; revision=2160

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

index 12df0260c0f0181a6f9ef97b05975b8c34b9b680..6e47bb19e76d6d0b197fa6c7fc378a5b82885286 100644 (file)
@@ -2,6 +2,7 @@
 #include <KDebug>
 #include <QGraphicsSceneMouseEvent>
 #include <QGraphicsRectItem>
+#include <QGraphicsSvgItem>
 #include <QGraphicsView>
 #include <QCursor>
 #include <QList>
@@ -143,10 +144,9 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) {
                 }
                 t->setTextInteractionFlags(Qt::NoTextInteraction);
                 setCursor(Qt::ClosedHandCursor);
-            } else if (item->type() == 3) {
-                QGraphicsRectItem *gi = (QGraphicsRectItem*)item;
-                QRectF r = gi->rect();
-                r.translate(gi->scenePos());
+            } else if (item->type() == 3 || item->type() == 13 || item->type() == 7) {
+                QRectF r = item->boundingRect();
+                r.translate(item->scenePos());
                 if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
                     resizeMode = TopLeft;
                 } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
@@ -188,48 +188,57 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) {
 void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
 
     if (m_selectedItem && e->buttons() & Qt::LeftButton) {
-        if (m_selectedItem->type() == 3) {
-            QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
-            QRectF newrect = gi->rect();
+        if (m_selectedItem->type() == 3 || m_selectedItem->type() == 13 || m_selectedItem->type() == 7) {
+            QRectF newrect = m_selectedItem->boundingRect();
             QPointF newpoint = e->scenePos();
             //newpoint -= m_selectedItem->scenePos();
             switch (resizeMode) {
             case TopLeft:
-                newrect.setBottomRight(newrect.bottomRight() + gi->pos() - newpoint);
-                gi->setPos(newpoint);
+                newrect.setBottomRight(newrect.bottomRight() + m_selectedItem->pos() - newpoint);
+                m_selectedItem->setPos(newpoint);
                 break;
             case BottomLeft:
-                newrect.setBottomRight(QPointF(newrect.bottomRight().x() + gi->pos().x() - newpoint.x(), newpoint.y() - gi->pos().y()));
-                gi->setPos(QPointF(newpoint.x(), gi->pos().y()));
+                newrect.setBottomRight(QPointF(newrect.bottomRight().x() + m_selectedItem->pos().x() - newpoint.x(), newpoint.y() - m_selectedItem->pos().y()));
+                m_selectedItem->setPos(QPointF(newpoint.x(), m_selectedItem->pos().y()));
                 break;
             case TopRight:
-                newrect.setBottomRight(QPointF(newpoint.x() - gi->pos().x(), newrect.bottom() + gi->pos().y() - newpoint.y()));
-                gi->setPos(QPointF(gi->pos().x(), newpoint.y()));
+                newrect.setBottomRight(QPointF(newpoint.x() - m_selectedItem->pos().x(), newrect.bottom() + m_selectedItem->pos().y() - newpoint.y()));
+                m_selectedItem->setPos(QPointF(m_selectedItem->pos().x(), newpoint.y()));
                 break;
             case BottomRight:
-                newrect.setBottomRight(newpoint - gi->pos());
+                newrect.setBottomRight(newpoint - m_selectedItem->pos());
                 break;
             case Left:
-                newrect.setRight(gi->pos().x() + newrect.width() - newpoint.x());
-                gi->setPos(QPointF(newpoint.x(), gi->pos().y()));
+                newrect.setRight(m_selectedItem->pos().x() + newrect.width() - newpoint.x());
+                m_selectedItem->setPos(QPointF(newpoint.x(), m_selectedItem->pos().y()));
                 break;
             case Right:
-                newrect.setRight(newpoint.x() - gi->pos().x());
+                newrect.setRight(newpoint.x() - m_selectedItem->pos().x());
                 break;
             case Up:
-                newrect.setBottom(gi->pos().y() + newrect.bottom() - newpoint.y());
-                gi->setPos(QPointF(gi->pos().x(), newpoint.y()));
+                newrect.setBottom(m_selectedItem->pos().y() + newrect.bottom() - newpoint.y());
+                m_selectedItem->setPos(QPointF(m_selectedItem->pos().x(), newpoint.y()));
                 break;
             case Down:
-                newrect.setBottom(newpoint.y() - gi->pos().y());
+                newrect.setBottom(newpoint.y() - m_selectedItem->pos().y());
                 break;
             default:
                 QPointF diff = e->scenePos() - m_clickPoint;
                 m_clickPoint = e->scenePos();
-                gi->moveBy(diff.x(), diff.y());
+                m_selectedItem->moveBy(diff.x(), diff.y());
                 break;
             }
-            gi->setRect(newrect);
+            if (m_selectedItem->type() == 3) {
+                QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
+                gi->setRect(newrect);
+            }
+            /*else {
+            qreal s;
+            if (resizeMode == Left || resizeMode == Right ) s = m_selectedItem->boundingRect().width() / newrect.width();
+            else s = m_selectedItem->boundingRect().height() / newrect.height();
+            m_selectedItem->scale( 1 / s, 1 / s );
+            kDebug()<<"/// SCALING SVG, RESIZE MODE: "<<resizeMode<<", RECT:"<<m_selectedItem->boundingRect();
+            }*/
             //gi->setPos(m_selectedItem->scenePos());
             /*if (resizeMode == NoResize) {
                 QGraphicsScene::mouseMoveEvent(e);
@@ -253,10 +262,13 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
         resizeMode = NoResize;
         bool itemFound = false;
         foreach(QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) {
-            if (g->type() == 3 && g->zValue() > -1000) {
-                QGraphicsRectItem *gi = (QGraphicsRectItem*)g;
-                QRectF r = gi->rect();
-                r.translate(gi->scenePos());
+            if ((g->type() == 13 || g->type() == 7) && g->zValue() > -1000) {
+                // image or svg item
+                setCursor(Qt::OpenHandCursor);
+                break;
+            } else if (g->type() == 3 && g->zValue() > -1000) {
+                QRectF r = g->boundingRect();
+                r.translate(g->scenePos());
                 itemFound = true;
                 if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
                     setCursor(QCursor(Qt::SizeFDiagCursor));
index ca30117bb178bfa2e58e658a051ac14a1c09a91d..5a5b005e9f4a2844f0a9d89c671cefefb46e4d1b 100644 (file)
@@ -21,6 +21,7 @@
 #include <QGraphicsItem>
 #include <QGraphicsRectItem>
 #include <QGraphicsTextItem>
+#include <QGraphicsSvgItem>
 #include <KDebug>
 #include <QFile>
 #include <KTemporaryFile>
@@ -50,6 +51,14 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv,
         QGraphicsTextItem *t;
 
         switch (item->type()) {
+        case 7:
+            e.setAttribute("type", "QGraphicsPixmapItem");
+            content.setAttribute("url", item->data(Qt::UserRole).toString());
+            break;
+        case 13:
+            e.setAttribute("type", "QGraphicsSvgItem");
+            content.setAttribute("url", item->data(Qt::UserRole).toString());
+            break;
         case 3:
             e.setAttribute("type", "QGraphicsRectItem");
             content.setAttribute("rect", rectFToString(((QGraphicsRectItem*)item)->rect()));
@@ -63,12 +72,12 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv,
             //content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml()));
             content.appendChild(doc.createTextNode(t->toPlainText()));
             font = t->font();
-            e.setAttribute("font", font.family());
-            e.setAttribute("font-bold", font.bold());
-            e.setAttribute("font-size", font.pointSize());
-            e.setAttribute("font-italic", font.italic());
-            e.setAttribute("font-underline", font.underline());
-            e.setAttribute("font-color", colorToString(t->defaultTextColor()));
+            content.setAttribute("font", font.family());
+            content.setAttribute("font-bold", font.bold());
+            content.setAttribute("font-size", font.pointSize());
+            content.setAttribute("font-italic", font.italic());
+            content.setAttribute("font-underline", font.underline());
+            content.setAttribute("font-color", colorToString(t->defaultTextColor()));
             break;
         default:
             continue;
@@ -155,12 +164,12 @@ int TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv,
                 int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt();
                 if (zValue > -1000)
                     if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") {
-                        QFont font(items.item(i).attributes().namedItem("font").nodeValue());
-                        font.setBold(items.item(i).attributes().namedItem("font-bold").nodeValue().toInt());
-                        font.setItalic(items.item(i).attributes().namedItem("font-italic").nodeValue().toInt());
-                        font.setUnderline(items.item(i).attributes().namedItem("font-underline").nodeValue().toInt());
-                        font.setPointSize(items.item(i).attributes().namedItem("font-size").nodeValue().toInt());
-                        QColor col(stringToColor(items.item(i).attributes().namedItem("font-color").nodeValue()));
+                        QFont font(items.item(i).namedItem("content").attributes().namedItem("font").nodeValue());
+                        font.setBold(items.item(i).namedItem("content").attributes().namedItem("font-bold").nodeValue().toInt());
+                        font.setItalic(items.item(i).namedItem("content").attributes().namedItem("font-italic").nodeValue().toInt());
+                        font.setUnderline(items.item(i).namedItem("content").attributes().namedItem("font-underline").nodeValue().toInt());
+                        font.setPointSize(items.item(i).namedItem("content").attributes().namedItem("font-size").nodeValue().toInt());
+                        QColor col(stringToColor(items.item(i).namedItem("content").attributes().namedItem("font-color").nodeValue()));
                         QGraphicsTextItem *txt = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font);
                         txt->setDefaultTextColor(col);
                         txt->setTextInteractionFlags(Qt::NoTextInteraction);
@@ -173,7 +182,21 @@ int TitleDocument::loadDocument(const KUrl& url , QGraphicsPolygonItem* startv,
                             double penwidth = items.item(i).namedItem("content").attributes().namedItem("penwidth").nodeValue().toDouble();
                             QGraphicsRectItem *rec = scene->addRect(stringToRect(rect), QPen(QBrush(stringToColor(pen_str)), penwidth), QBrush(stringToColor(br_str)));
                             gitem = rec;
-                        }
+                        } else
+                            if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsPixmapItem") {
+                                QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
+                                QPixmap pix(url);
+                                QGraphicsPixmapItem *rec = scene->addPixmap(pix);
+                                rec->setData(Qt::UserRole, url);
+                                gitem = rec;
+                            } else
+                                if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsSvgItem") {
+                                    QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
+                                    QGraphicsSvgItem *rec = new QGraphicsSvgItem(url);
+                                    scene->addItem(rec);
+                                    rec->setData(Qt::UserRole, url);
+                                    gitem = rec;
+                                }
                 //pos and transform
                 if (gitem) {
                     QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(),
index 83a03d1ff32be7a63f26b4f84525ee5db5202b59..a79cdba5710401a84a15173b87a6bac40feaae5a 100644 (file)
@@ -72,7 +72,6 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
     connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
 
     connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
-    connect(svgfilename, SIGNAL(urlSelected(const KUrl&)), this, SLOT(svgSelected(const KUrl &)));
     connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
     connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
 
@@ -107,7 +106,7 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
     connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
 
     m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image"));
-    m_buttonImage->setCheckable(true);
+    m_buttonImage->setCheckable(false);
     connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
 
     m_buttonCursor = m_toolbar->addAction(KIcon("select-rectangular"), i18n("Selection Tool"));
@@ -172,7 +171,6 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
     //graphicsView->resize(400, 300);
     kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
     toolBox->setItemEnabled(2, false);
-    toolBox->setItemEnabled(3, false);
     if (!url.isEmpty()) {
         m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
         slotSelectTool();
@@ -191,7 +189,6 @@ void TitleWidget::slotTextTool() {
     m_scene->setTool(TITLE_TEXT);
     m_buttonRect->setChecked(false);
     m_buttonCursor->setChecked(false);
-    m_buttonImage->setChecked(false);
 }
 
 void TitleWidget::slotRectTool() {
@@ -200,7 +197,6 @@ void TitleWidget::slotRectTool() {
     m_scene->setTool(TITLE_RECTANGLE);
     m_buttonText->setChecked(false);
     m_buttonCursor->setChecked(false);
-    m_buttonImage->setChecked(false);
 }
 
 void TitleWidget::slotSelectTool() {
@@ -208,7 +204,31 @@ void TitleWidget::slotSelectTool() {
     m_buttonCursor->setChecked(true);
     m_buttonText->setChecked(false);
     m_buttonRect->setChecked(false);
-    m_buttonImage->setChecked(false);
+}
+
+void TitleWidget::slotImageTool() {
+    KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
+    if (!url.isEmpty()) {
+        if (url.path().endsWith(".svg")) {
+            QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
+            svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+            svg->setZValue(m_count++);
+            svg->setData(Qt::UserRole, url.path());
+            graphicsView->scene()->addItem(svg);
+        } else {
+            QPixmap pix(url.path());
+            QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
+            image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
+            image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+            image->setData(Qt::UserRole, url.path());
+            image->setZValue(m_count++);
+            graphicsView->scene()->addItem(image);
+        }
+    }
+    m_scene->setTool(TITLE_SELECT);
+    m_buttonRect->setChecked(false);
+    m_buttonCursor->setChecked(true);
+    m_buttonText->setChecked(false);
 }
 
 void TitleWidget::displayBackgroundFrame() {
@@ -402,8 +422,8 @@ void TitleWidget::selectionChanged() {
             frame_properties->setEnabled(false);
         }
         zValue->setValue((int)l[0]->zValue());
-        itemzoom->setValue((int)transformations[l[0]].scalex*100);
-        itemrotate->setValue((int)transformations[l[0]].rotate);
+        itemzoom->setValue((int)(transformations[l[0]].scalex * 100));
+        itemrotate->setValue((int)(transformations[l[0]].rotate));
         value_x->blockSignals(false);
         value_y->blockSignals(false);
         value_w->blockSignals(false);
@@ -498,12 +518,6 @@ void TitleWidget::fontBold() {
     }
 }
 
-void TitleWidget::svgSelected(const KUrl& u) {
-    QGraphicsSvgItem *svg = new QGraphicsSvgItem(u.toLocalFile());
-    svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
-    graphicsView->scene()->addItem(svg);
-}
-
 void TitleWidget::itemScaled(int val) {
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     if (l.size() == 1) {
@@ -552,7 +566,7 @@ void TitleWidget::setupViewports() {
 }
 
 void TitleWidget::loadTitle() {
-    KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, tr("Save Title"));
+    KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Load Title"));
     if (!url.isEmpty()) {
         QList<QGraphicsItem *> items = m_scene->items();
         for (int i = 0; i < items.size(); i++) {
@@ -564,7 +578,7 @@ void TitleWidget::loadTitle() {
 }
 
 void TitleWidget::saveTitle(KUrl url) {
-    if (url.isEmpty()) KUrl url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, tr("Save Title"));
+    if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Save Title"));
     if (!url.isEmpty()) m_titledocument.saveDocument(url, startViewport, endViewport);
 }
 
index e213b7790567ad1118957348cc325ff0558f8cc3..e6c837d1dc616145a3b8d460127ced82aab1d172 100644 (file)
@@ -80,7 +80,6 @@ public slots:
     void fontBold();
     void setupViewports();
     void zIndexChanged(int);
-    void svgSelected(const KUrl&);
     void itemScaled(int);
     void itemRotate(int);
     void saveTitle(KUrl url = KUrl());
@@ -99,6 +98,7 @@ private slots:
     void slotTextTool();
     void slotRectTool();
     void slotSelectTool();
+    void slotImageTool();
 };
 
 
index dd95e59458aab54ad123061b9fc781d9535f01eb..a9d5fa69064676240300dd238a5943d74b54917f 100644 (file)
      <widget class="QGraphicsView" name="graphicsView" />
      <widget class="QToolBox" name="toolBox" >
       <property name="currentIndex" >
-       <number>0</number>
+       <number>1</number>
       </property>
       <widget class="QWidget" name="BasicOperations" >
        <property name="geometry" >
          <x>0</x>
          <y>0</y>
          <width>309</width>
-         <height>108</height>
+         <height>140</height>
         </rect>
        </property>
        <attribute name="label" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>381</width>
-         <height>157</height>
+         <width>309</width>
+         <height>140</height>
         </rect>
        </property>
        <attribute name="label" >
         </item>
        </layout>
       </widget>
-      <widget class="QWidget" name="SVG" >
-       <property name="geometry" >
-        <rect>
-         <x>0</x>
-         <y>0</y>
-         <width>381</width>
-         <height>157</height>
-        </rect>
-       </property>
-       <attribute name="label" >
-        <string>SVG</string>
-       </attribute>
-       <layout class="QGridLayout" >
-        <item row="0" column="0" >
-         <layout class="QVBoxLayout" >
-          <item>
-           <widget class="QLabel" name="label_13" >
-            <property name="sizePolicy" >
-             <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
-              <horstretch>0</horstretch>
-              <verstretch>0</verstretch>
-             </sizepolicy>
-            </property>
-            <property name="text" >
-             <string>Filename:</string>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="KUrlRequester" name="svgfilename" >
-            <property name="filter" >
-             <string>*.svg *.svgz</string>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <spacer>
-            <property name="orientation" >
-             <enum>Qt::Vertical</enum>
-            </property>
-            <property name="sizeType" >
-             <enum>QSizePolicy::Expanding</enum>
-            </property>
-            <property name="sizeHint" stdset="0" >
-             <size>
-              <width>20</width>
-              <height>151</height>
-             </size>
-            </property>
-           </spacer>
-          </item>
-         </layout>
-        </item>
-       </layout>
-      </widget>
       <widget class="QWidget" name="Seite" >
        <property name="geometry" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>362</width>
+         <width>273</width>
          <height>224</height>
         </rect>
        </property>
    <extends>QSpinBox</extends>
    <header>knuminput.h</header>
   </customwidget>
-  <customwidget>
-   <class>KUrlRequester</class>
-   <extends>QFrame</extends>
-   <header>kurlrequester.h</header>
-  </customwidget>
  </customwidgets>
  <resources/>
  <connections>