]> git.sesse.net Git - kdenlive/commitdiff
load and save titles (except svg's)
authorMarco Gittler <marco@gitma.de>
Sun, 2 Mar 2008 13:42:55 +0000 (13:42 +0000)
committerMarco Gittler <marco@gitma.de>
Sun, 2 Mar 2008 13:42:55 +0000 (13:42 +0000)
svn path=/branches/KDE4/; revision=1972

src/complexparameter.cpp
src/parameterplotter.cpp
src/titledocument.cpp [new file with mode: 0644]
src/titledocument.h [new file with mode: 0644]
src/titlewidget.cpp
src/titlewidget.h
src/widgets/keyframewidget_ui.ui
src/widgets/titlewidget_ui.ui

index 4f3ce57a40c7afd7033149ab0aee817147bca2f8..0882b2f5e48d9535f8fe92133aa67009fcaec55d 100644 (file)
@@ -58,7 +58,7 @@ ComplexParameter::ComplexParameter(QWidget *parent)
        /*ÜeffectLists["audio"]=audioEffectList;
        effectLists["video"]=videoEffectList;
        effectLists["custom"]=customEffectList;*/
-       
+       setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
        ui.infoBox->hide();     
        updateButtonStatus();
        
index 6701638fb05cb181b2ec396247ddecd6e256af4f..988e9036140ca896c24c0d0d2a713eac951d66e2 100644 (file)
@@ -19,6 +19,7 @@
 #include <QVariant>
 #include <KPlotObject>
 #include <QMouseEvent>
+#include <QPen>
 #include <KDebug>
 #include <KPlotPoint>
 
@@ -105,7 +106,7 @@ void ParameterPlotter::setPointLists(const QDomElement& d,int startframe,int end
                        }
                        if (defaults[i].toDouble()>max_y)
                                defaults[i]=max_y;
-                       plot->addPoint(startframe,defaults[i].toInt()*stretchFactors[i]);
+                       plot->addPoint(startframe,defaults[i].toInt()*stretchFactors[i],parameterNameList[i]);
                        //add keyframes here
                        plot->addPoint(endframe,defaults[i].toInt()*stretchFactors[i]);
                
@@ -164,7 +165,7 @@ void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
                foreach (KPlotObject *o, plotObjects() ){
                        QList<KPlotPoint*> points=o->points();
                        for(int p=0;p<points.size();p++){
-                               if (points[p]==movepoint){
+                               if (points[p]==movepoint && (activeIndexPlot==-1 || activeIndexPlot==i ) ){
                                        QPoint delta=event->pos()-oldmousepoint;
                                        double newy=movepoint->y()-delta.y()*dataRect().height()/pixRect().height();
                                        if (m_moveY && newy>min_y && newy<max_y)
@@ -191,9 +192,13 @@ void ParameterPlotter::replot(const QString & name){
        int i=0;
        bool drawAll=name.isEmpty() || name=="all";
        activeIndexPlot=-1;
-       foreach (KPlotObject* p,plotObjects() ){
+       
+       foreach (KPlotObject* p, plotObjects() ){
                p->setShowPoints(drawAll || parameterNameList[i]==name);
                p->setShowLines(drawAll || parameterNameList[i]==name);
+               QPen pen=(drawAll || parameterNameList[i]==name ? QPen(Qt::SolidLine) : QPen(Qt::NoPen) );
+               pen.setColor(p->linePen().color());
+               p->setLabelPen(pen);
                if ( parameterNameList[i]==name )
                        activeIndexPlot = i;
                replacePlotObject(i++,p);
diff --git a/src/titledocument.cpp b/src/titledocument.cpp
new file mode 100644 (file)
index 0000000..ab41c53
--- /dev/null
@@ -0,0 +1,213 @@
+/***************************************************************************
+                          titledocument.h  -  description
+                             -------------------
+    begin                : Feb 28 2008
+    copyright            : (C) 2008 by Marco Gittler
+    email                : g.marco@freenet.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#include "titledocument.h"
+#include <QGraphicsScene>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QGraphicsItem>
+#include <QGraphicsRectItem>
+#include <QGraphicsTextItem>
+#include <KDebug>
+#include <QFile>
+#include <kio/netaccess.h>
+
+TitleDocument::TitleDocument(){
+       scene=NULL;     
+}
+
+void TitleDocument::setScene(QGraphicsScene* _scene){
+       scene=_scene;
+}
+
+bool TitleDocument::saveDocument(const KUrl& url,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv){
+       QDomDocument doc;
+       
+       if (!scene)
+               return false;
+       
+       QDomElement main=doc.createElement("kdenlivetitle");
+       doc.appendChild(main);
+       
+       foreach(QGraphicsItem* item, scene->items()){
+               QDomElement e=doc.createElement("item");
+               QDomElement content=doc.createElement("content");
+
+               switch (item->type()){
+                       case 3:
+                               e.setAttribute("type","QGraphicsRectItem");
+                               content.setAttribute("rect",rectFToString(((QGraphicsRectItem*)item)->rect() ));
+                               content.setAttribute("pencolor",colorToString(((QGraphicsRectItem*)item)->pen().color()) );
+                               content.setAttribute("penwidth",((QGraphicsRectItem*)item)->pen().width() );
+                               content.setAttribute("brushcolor",colorToString(((QGraphicsRectItem*)item)->brush().color()) );
+                               break;
+                       case 8:
+                               e.setAttribute("type","QGraphicsTextItem");
+                               content.appendChild(doc.createTextNode( ((QGraphicsTextItem*)item)->toHtml() ) );
+                               break;
+                       default:
+                               continue;
+               }
+               QDomElement pos=doc.createElement("position");
+               pos.setAttribute("x",item->pos().x());
+               pos.setAttribute("y",item->pos().y());
+               QTransform transform=item->transform();
+               QDomElement tr=doc.createElement("transform");
+               tr.appendChild(doc.createTextNode(
+                 QString("%1,%2,%3,%4,%5,%6,%7,%8,%9").arg(
+                   transform.m11()).arg(transform.m12()).arg(transform.m13()).arg(transform.m21()).arg(transform.m22()).arg(transform.m23()).arg(transform.m31()).arg(transform.m32()).arg(transform.m33())
+                 )
+               );
+               pos.appendChild(tr);
+               
+               
+               e.appendChild(pos);
+               e.appendChild(content);
+               main.appendChild(e);
+       }
+       if (startv && endv){
+               QDomElement endp=doc.createElement("endviewport");
+               QDomElement startp=doc.createElement("startviewport");
+               endp.setAttribute("x",endv->pos().x());
+               endp.setAttribute("y",endv->pos().y());
+               endp.setAttribute("size",endv->sceneBoundingRect().width()/2);
+               
+               startp.setAttribute("x",startv->pos().x());
+               startp.setAttribute("y",startv->pos().y());
+               startp.setAttribute("size",startv->sceneBoundingRect().width()/2);
+               
+               main.appendChild(startp);
+               main.appendChild(endp);
+       }
+       QDomElement backgr=doc.createElement("background");
+       backgr.setAttribute("color",colorToString(scene->backgroundBrush().color()));
+       main.appendChild(backgr);
+       
+       QString tmpfile="/tmp/newtitle";
+       QFile xmlf(tmpfile);
+       xmlf.open(QIODevice::WriteOnly);
+       xmlf.write(doc.toString().toAscii());
+       xmlf.close();
+       kDebug() << KIO::NetAccess::upload(tmpfile,url,0);
+}
+
+bool TitleDocument::loadDocument(const KUrl& url ,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) {
+       QString tmpfile;
+       QDomDocument doc;
+       double aspect_ratio=4.0/3.0;
+       if (!scene)
+               return false;
+       
+       if (KIO::NetAccess::download(url, tmpfile, 0)) {
+               QFile file(tmpfile);
+               if (file.open(QIODevice::ReadOnly)) {
+                       doc.setContent(&file, false);
+                       file.close();
+               }else
+                       return false;
+               KIO::NetAccess::removeTempFile(tmpfile);
+               QDomNodeList titles=doc.elementsByTagName("kdenlivetitle");
+               if (titles.size()){
+                       
+                       QDomNodeList items=titles.item(0).childNodes();
+                       for(int i=0;i<items.count();i++){
+                               QGraphicsItem *gitem=NULL;
+                               kDebug() << items.item(i).attributes().namedItem("type").nodeValue();
+                               if (items.item(i).attributes().namedItem("type").nodeValue()=="QGraphicsTextItem"){
+                                       QGraphicsTextItem *txt=scene->addText("");
+                                       txt->setHtml(items.item(i).namedItem("content").firstChild().nodeValue());
+                                       gitem=txt;
+                               }else
+                               if (items.item(i).attributes().namedItem("type").nodeValue()=="QGraphicsRectItem"){
+                                       QString rect=items.item(i).namedItem("content").attributes().namedItem("rect").nodeValue();
+                                       QString br_str=items.item(i).namedItem("content").attributes().namedItem("brushcolor").nodeValue();
+                                       QString pen_str=items.item(i).namedItem("content").attributes().namedItem("pencolor").nodeValue();
+                                       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;
+                               }
+                               //pos and transform
+                               if (gitem ){
+                                       QPointF p(items.item(i).namedItem("position").attributes().namedItem("x").nodeValue().toDouble(),
+                                               items.item(i).namedItem("position").attributes().namedItem("y").nodeValue().toDouble());
+                                       gitem->setPos(p);
+                                       gitem->setTransform(stringToTransform(items.item(i).namedItem("position").firstChild().firstChild().nodeValue()));
+                               }
+                               if (items.item(i).nodeName()=="background"){
+                                       kDebug() << items.item(i).attributes().namedItem("color").nodeValue();
+                                       scene->setBackgroundBrush(QBrush(stringToColor(items.item(i).attributes().namedItem("color").nodeValue())));
+                               }else   if (items.item(i).nodeName()=="startviewport" && startv){
+                                       QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(),items.item(i).attributes().namedItem("y").nodeValue().toDouble());
+                                       double width=items.item(i).attributes().namedItem("size").nodeValue().toDouble();
+                                       QRectF rect(-width,-width/aspect_ratio,width*2.0,width/aspect_ratio*2.0);
+                                       kDebug() << width << rect;
+                                       startv->setPolygon(rect);
+                                       startv->setPos(p);
+                               }else   if (items.item(i).nodeName()=="endviewport" && endv){
+                                       QPointF p(items.item(i).attributes().namedItem("x").nodeValue().toDouble(),items.item(i).attributes().namedItem("y").nodeValue().toDouble());
+                                       double width=items.item(i).attributes().namedItem("size").nodeValue().toDouble();
+                                       QRectF rect(-width,-width/aspect_ratio,width*2.0,width/aspect_ratio*2.0);
+                                       kDebug() << width << rect;
+                                       endv->setPolygon(rect);
+                                       endv->setPos(p);
+                               }
+                               
+                       }
+                       
+                       
+               }
+               
+               
+       }
+       return true;
+}
+
+QString TitleDocument::colorToString(const QColor& c){
+       QString ret="%1,%2,%3,%4";
+       ret=ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
+       return ret;
+}
+
+QString TitleDocument::rectFToString(const QRectF& c){
+       QString ret="%1,%2,%3,%4";
+       ret=ret.arg(c.x()).arg(c.y()).arg(c.width()).arg(c.height());
+       return ret;
+}
+
+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());
+}
+
+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());;
+}
+QTransform TitleDocument::stringToTransform(const QString& s){
+       QStringList l=s.split(",");
+       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()
+               );
+}
diff --git a/src/titledocument.h b/src/titledocument.h
new file mode 100644 (file)
index 0000000..47733a7
--- /dev/null
@@ -0,0 +1,41 @@
+/***************************************************************************
+                          titledocument.h  -  description
+                             -------------------
+    begin                : Feb 28 2008
+    copyright            : (C) 2008 by Marco Gittler
+    email                : g.marco@freenet.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#ifndef TITLEDOCUMENT_H
+#define TITLEDOCUMENT_H
+#include <KUrl>
+
+class QGraphicsScene;
+class QGraphicsPolygonItem;
+
+class TitleDocument {
+       QGraphicsScene* scene;
+       public:
+               TitleDocument();
+               void setScene(QGraphicsScene* scene);
+               bool saveDocument(const KUrl& url,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv);
+               bool loadDocument(const KUrl& url,QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv);
+       private:
+               QString colorToString(const QColor&);
+               QString rectFToString(const QRectF&);
+               QRectF stringToRect(const QString &);
+               QColor stringToColor(const QString &);
+               QTransform stringToTransform(const QString &);
+};
+
+#endif
+
+
index 24e4d37f72d75930552e46db19ae46d140a1037f..4614ec4c326e9d9ff485dd3a4c7b929fd65660d6 100644 (file)
 #include "titlewidget.h"
 #include "graphicsscenerectmove.h"
 #include <QGraphicsView>
+#include <QDomDocument>
 #include <KDebug>
 #include <QGraphicsItem>
 #include <QGraphicsSvgItem>
+#include <KFileDialog>
 
 int settingUp=false;
 
@@ -33,6 +35,9 @@ TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
        connect (ktextedit, SIGNAL(textChanged()), this , SLOT (textChanged()));
        connect (fontColorButton, SIGNAL ( clicked()), this, SLOT( textChanged()) ) ;
        //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ;
+       connect (loadButton, SIGNAL ( clicked()), this, SLOT( loadTitle() ) ) ;
+       connect (saveButton, SIGNAL ( clicked()), this, SLOT( saveTitle() ) ) ;
+       
        
        connect (kfontrequester, SIGNAL ( fontSelected(const QFont &)), this, SLOT( textChanged()) ) ;
        connect(textAlpha, SIGNAL( valueChanged(int) ), this, SLOT (textChanged()));
@@ -64,6 +69,7 @@ TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
        //scene->setBackgroundBrush(*gradient);
        
        graphicsView->setScene(scene);
+       m_titledocument.setScene(scene);
        connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
        initViewports();
        
@@ -158,9 +164,9 @@ void TitleWidget::selectionChanged(){
                else{
                        //toolBox->setCurrentIndex(0);
                }
-               zValue->setValue(l[0]->zValue());
-               itemzoom->setValue(transformations[l[0]].scalex*100);
-               itemrotate->setValue(transformations[l[0]].rotate);
+               zValue->setValue((int)l[0]->zValue());
+               itemzoom->setValue((int)transformations[l[0]].scalex*100);
+               itemrotate->setValue((int)transformations[l[0]].rotate);
        }
 }
 
@@ -236,17 +242,31 @@ void TitleWidget::itemRotate(int val) {
 void TitleWidget::setupViewports(){
        double aspect_ratio=4.0/3.0;//read from project
        
-       QRectF sp(startViewportX->value(), startViewportY->value(),0,0);
-       QRectF ep(endViewportX->value(),endViewportY->value(),0,0);
+       QRectF sp(0,0,0,0);
+       QRectF ep(0,0,0,0);
        
        double sv_size=startViewportSize->value();
        double ev_size=endViewportSize->value();
        sp.adjust(-sv_size,-sv_size/aspect_ratio,sv_size,sv_size/aspect_ratio);
        ep.adjust(-ev_size,-ev_size/aspect_ratio,ev_size,ev_size/aspect_ratio); 
        
+       startViewport->setPos(startViewportX->value(), startViewportY->value());
+       endViewport->setPos(endViewportX->value(),endViewportY->value());
+       
        startViewport->setPolygon(QPolygonF(sp));
        endViewport->setPolygon(QPolygonF(ep));
        
 }
+
+void TitleWidget::loadTitle(){
+       KUrl url= KFileDialog::getOpenUrl( KUrl(), "*.kdenlivetitle",this,tr("Save Title"));
+       m_titledocument.loadDocument(url,startViewport,endViewport);
+}
+
+void TitleWidget::saveTitle(){
+       KUrl url= KFileDialog::getSaveUrl( KUrl(), "*.kdenlivetitle",this,tr("Save Title"));
+       m_titledocument.saveDocument(url,startViewport,endViewport);
+}
+
 #include "moc_titlewidget.cpp"
 
index 494a0c7a9c1c31dd908e19fa0b751ef06514ae15..c6c9362bb8c82bf17612389bdac543e55295d0e5 100644 (file)
@@ -19,6 +19,7 @@
 #define TITLEWIDGET_H
 
 #include "ui_titlewidget_ui.h"
+#include "titledocument.h"
 #include <QDialog>
 #include <QMap>
 
@@ -41,6 +42,7 @@ private:
        QGraphicsPolygonItem *startViewport,*endViewport;
        void initViewports();
        QMap<QGraphicsItem*,Transform > transformations;
+       TitleDocument m_titledocument;
 public slots:
        void slotNewText();
        void slotNewRect();
@@ -54,6 +56,8 @@ public slots:
        void svgSelected(const KUrl&);
        void itemScaled(int);
        void itemRotate(int);
+       void saveTitle();
+       void loadTitle();
 };
 
 
index 6a61a93fdff72ef752284a3423119f95b1483264..a0c64c74a5a11277363cde7f08f8392ff709e00c 100644 (file)
   </property>
   <layout class="QGridLayout" >
    <item row="0" column="0" >
-    <widget class="QSplitter" name="splitter" >
-     <property name="orientation" >
-      <enum>Qt::Vertical</enum>
-     </property>
-     <widget class="ParameterPlotter" name="kplotwidget" />
-     <widget class="QWidget" name="" >
+    <layout class="QVBoxLayout" >
+     <item>
+      <widget class="ParameterPlotter" name="kplotwidget" >
+       <property name="sizePolicy" >
+        <sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="minimumSize" >
+        <size>
+         <width>150</width>
+         <height>200</height>
+        </size>
+       </property>
+      </widget>
+     </item>
+     <item>
       <layout class="QHBoxLayout" >
        <item>
         <widget class="QToolButton" name="buttonLeftRight" >
         </widget>
        </item>
       </layout>
-     </widget>
-     <widget class="KTextEdit" name="infoBox" />
-    </widget>
+     </item>
+     <item>
+      <widget class="KTextEdit" name="infoBox" />
+     </item>
+    </layout>
    </item>
   </layout>
  </widget>
index abfa6e48527b4c23cd59872c17bd56aebe5702b7..06c679473a37315b9399a147db06fefe2a1f0d4e 100644 (file)
         </widget>
        </item>
        <item>
-        <widget class="QPushButton" name="pushButton" >
+        <widget class="QPushButton" name="loadButton" >
          <property name="text" >
           <string>Load Title</string>
          </property>
         </widget>
        </item>
        <item>
-        <widget class="QPushButton" name="pushButton_2" >
+        <widget class="QPushButton" name="saveButton" >
          <property name="text" >
           <string>Save Title</string>
          </property>
          </sizepolicy>
         </property>
         <property name="currentIndex" >
-         <number>0</number>
+         <number>2</number>
         </property>
         <widget class="QWidget" name="BasicOperations" >
          <property name="geometry" >
           <rect>
            <x>0</x>
            <y>0</y>
-           <width>339</width>
+           <width>488</width>
            <height>304</height>
           </rect>
          </property>
          </attribute>
          <layout class="QGridLayout" >
           <item row="0" column="0" >
-           <layout class="QVBoxLayout" >
-            <item>
+           <layout class="QGridLayout" >
+            <item row="0" column="0" >
              <widget class="KColorButton" name="kcolorbutton" />
             </item>
-            <item>
+            <item row="1" column="0" >
              <widget class="QSlider" name="horizontalSlider" >
               <property name="maximum" >
                <number>255</number>
               </property>
              </widget>
             </item>
-            <item>
+            <item row="2" column="0" >
              <spacer>
               <property name="orientation" >
                <enum>Qt::Vertical</enum>
           <rect>
            <x>0</x>
            <y>0</y>
-           <width>208</width>
-           <height>167</height>
+           <width>488</width>
+           <height>304</height>
           </rect>
          </property>
          <attribute name="label" >
           <rect>
            <x>0</x>
            <y>0</y>
-           <width>152</width>
-           <height>229</height>
+           <width>488</width>
+           <height>304</height>
           </rect>
          </property>
          <attribute name="label" >