]> git.sesse.net Git - kdenlive/commitdiff
More work on title widget:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 31 Mar 2008 22:43:10 +0000 (22:43 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 31 Mar 2008 22:43:10 +0000 (22:43 +0000)
*disable textedit for now, it doesn't seem possible to make it work in sync with the qgraphicstextitem - for example selection in the 2 widgets cannot easily be synced, and the textedit->toHtml does not support color transparency...

* add picture of current project frame as background

svn path=/branches/KDE4/; revision=2154

src/graphicsscenerectmove.cpp
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/projectlist.cpp
src/titlewidget.cpp
src/titlewidget.h
src/widgets/titlewidget_ui.ui

index d6bd318893dd7601905702e5c1d38d70b99a539e..e5590cbaf203140db816141fdb5e74f56c173ce4 100644 (file)
@@ -91,7 +91,7 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) {
             }
         }
     }
-    if (!hasSelected) QGraphicsScene::mousePressEvent(e);
+    QGraphicsScene::mousePressEvent(e);
 
     kDebug() << "//////  MOUSE CLICK, RESIZE MODE: " << resizeMode;
 
@@ -170,15 +170,13 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
         QPointF p = e->scenePos();
         p += QPoint(-2, -2);
         resizeMode = NoResize;
-
+       bool itemFound = false;
         foreach(QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) {
-
             if (g->type() == 3) {
-
                 QGraphicsRectItem *gi = (QGraphicsRectItem*)g;
                 QRectF r = gi->rect();
                 r.translate(gi->scenePos());
-
+               itemFound = true;
                 if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
                     setCursor(QCursor(Qt::SizeFDiagCursor));
                 } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
@@ -196,8 +194,9 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
                 } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) {
                     setCursor(Qt::SizeVerCursor);
                 } else setCursor(QCursor(Qt::ArrowCursor));
+               break;
             }
-            break;
+           if (!itemFound) setCursor(QCursor(Qt::ArrowCursor));
         }
         QGraphicsScene::mouseMoveEvent(e);
     }
index e94b0ccd6681600535dcd57cf59d41ecf3e7e89c..692500194c6bd1ca6483ca54de41285912634574 100644 (file)
@@ -33,6 +33,7 @@
 #include "clipmanager.h"
 #include "addfoldercommand.h"
 #include "editfoldercommand.h"
+#include "titlewidget.h"
 
 KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false) {
     m_clipManager = new ClipManager(this);
@@ -367,5 +368,13 @@ void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color,
     setModified(true);
 }
 
+void KdenliveDoc::slotCreateTextClip(QString group, int groupId) {
+    TitleWidget *dia_ui = new TitleWidget(m_render, 0);
+    if (dia_ui->exec() == QDialog::Accepted) {
+    }
+    delete dia_ui;
+}
+
+
 #include "kdenlivedoc.moc"
 
index cd8c5afd35c280dcc23db98cbcd6e31c076ed107..8576101840c483419575bed04f2d999ab8e257c2 100644 (file)
@@ -106,6 +106,7 @@ private:
     bool m_modified;
 
 public slots:
+    void slotCreateTextClip(QString group, int groupId);
 
 signals:
     void addProjectClip(DocClipBase *);
index 6b5c37ffcc87b705b1c5ff103f4f501a9586861c..6c7d3f63cce64468d5300281fe39fab006c01410 100644 (file)
@@ -42,7 +42,6 @@
 #include "ui_colorclip_ui.h"
 
 #include "definitions.h"
-#include "titlewidget.h"
 #include "clipmanager.h"
 #include "docclipbase.h"
 #include "kdenlivedoc.h"
@@ -411,21 +410,21 @@ void ProjectList::slotAddColorClip() {
 }
 
 void ProjectList::slotAddTitleClip() {
-
-    if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!!  NO CMD STK";
-    //QDialog *dia = new QDialog;
-
-    TitleWidget *dia_ui = new TitleWidget(m_render, this);
-    //dia_ui->setupUi(dia);
-    //dia_ui->clip_name->setText(i18n("Title Clip"));
-    //dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
-    if (dia_ui->exec() == QDialog::Accepted) {
-        //QString color = dia_ui->clip_color->color().name();
-        //color = color.replace(0, 1, "0x") + "ff";
-        //m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), QString::null);
+    QString group = QString();
+    int groupId = -1;
+    ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
+    if (item && item->clipType() != FOLDER) {
+       while (item->parent()) {
+           item = static_cast <ProjectItem*>(item->parent());
+            if (item->clipType() == FOLDER) break;
+        }
     }
-    delete dia_ui;
-    //delete dia;
+    if (item && item->clipType() == FOLDER) {
+        group = item->groupName();
+        groupId = item->clipId();
+    }
+
+    m_doc->slotCreateTextClip(group, groupId);
 }
 void ProjectList::setDocument(KdenliveDoc *doc) {
     listView->clear();
index 6e457bd67c3755031ae533de514a7be289ae41bd..6e19ff1f9340462143b2f67b80aaa5529809bec2 100644 (file)
 
 #include <QGraphicsView>
 #include <QDomDocument>
-#include <KDebug>
-#include <KGlobalSettings>
 #include <QGraphicsItem>
 #include <QGraphicsSvgItem>
+#include <QTextDocumentFragment>
+#include <QTimer>
+
+#include <KDebug>
+#include <KGlobalSettings>
 #include <KFileDialog>
 
 #include "titlewidget.h"
@@ -33,20 +36,22 @@ int settingUp = false;
 TitleWidget::TitleWidget(Render *render, QWidget *parent): QDialog(parent) {
     setupUi(this);
     frame_properties->setFont(KGlobalSettings::toolBarFont());
+    toolBox->setFont(KGlobalSettings::toolBarFont());
     frame_properties->setEnabled(false);
     connect(newTextButton, SIGNAL(clicked()), this, SLOT(slotNewText()));
     connect(newRectButton, SIGNAL(clicked()), this, SLOT(slotNewRect()));
     connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
     connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
     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()));
+    ktextedit->setHidden(true);
+    connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
+    connect(font_family, SIGNAL(currentFontChanged (const QFont &)), this, SLOT(slotUpdateText())) ;
+    connect(font_size, SIGNAL(valueChanged (int)), this, SLOT(slotUpdateText())) ;
+    connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
     //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged()));
 
     connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
@@ -96,17 +101,27 @@ TitleWidget::TitleWidget(Render *render, QWidget *parent): QDialog(parent) {
     framepen.setColor(Qt::red);
     m_frameWidth = render->renderWidth();
     m_frameHeight = render->renderHeight();
+    QPixmap bg = render->extractFrame((int) render->seekPosition().frames(render->fps()), m_frameWidth, m_frameHeight);
+
+    QGraphicsPixmapItem *fb = new QGraphicsPixmapItem(bg);
+    fb->setZValue(-1000);
+    fb->setFlags(QGraphicsItem::ItemClipsToShape);
+    graphicsView->scene()->addItem(fb);
+
     m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
     m_frameBorder->setPen(framepen);
     m_frameBorder->setZValue(-1000);
     m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
     graphicsView->scene()->addItem(m_frameBorder);
+
     initViewports();
 
+
+
     graphicsView->show();
     graphicsView->setRenderHint(QPainter::Antialiasing);
     graphicsView->setInteractive(true);
-    slotAdjustZoom();
+    QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
     //graphicsView->resize(400, 300);
     kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
     toolBox->setItemEnabled(2, false);
@@ -189,7 +204,9 @@ void TitleWidget::slotNewText() {
     tt->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
     tt->setTextInteractionFlags(Qt::NoTextInteraction);
     tt->setPos(m_frameWidth / 2, m_frameHeight / 2);
-    tt->setFont(kfontrequester->font());
+    QFont font = font_family->currentFont();
+    font.setPointSize (font_size->value());
+    tt->setFont(font);
     connect(tt->document(), SIGNAL(contentsChanged()), this, SLOT(selectionChanged()));
     kDebug() << tt->metaObject()->className();
     /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
@@ -283,7 +300,7 @@ void TitleWidget::slotAdjustSelectedItem() {
 void TitleWidget::slotChangeBackground() {
     QColor color = kcolorbutton->color();
     color.setAlpha(horizontalSlider->value());
-    graphicsView->scene()->setBackgroundBrush(QBrush(color));
+    m_frameBorder->setBrush(QBrush(color));
 }
 
 void TitleWidget::textChanged() {
@@ -294,6 +311,38 @@ void TitleWidget::textChanged() {
     }
 }
 
+void TitleWidget::slotUpdateText() {
+    QFont font = font_family->currentFont();
+    font.setPointSize (font_size->value());
+    QColor color = fontColorButton->color();
+    color.setAlpha(textAlpha->value());
+
+    QGraphicsTextItem* item = NULL;
+    QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+    if (l.size() == 1 && (l[0])->type() == 8) {
+       item = (QGraphicsTextItem*)l[0];
+    }
+    if (!item) return;
+    if (item->textCursor().selection ().isEmpty()) 
+    {
+       item->setFont(font);
+       item->setDefaultTextColor(color);
+    }
+    /*else {
+       QTextDocumentFragment selec = item->textCursor().selection ();
+       selec.set
+    }*/
+    //if (ktextedit->textCursor().selectedText().isEmpty()) ktextedit->selectAll();
+
+    //ktextedit->setCurrentFont(font);
+    //ktextedit->setTextColor(color);
+    /*QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
+    if (l.size() == 1 && (l[0])->type() == 8 && l[0]->hasFocus()) {
+       QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
+       //item-
+    }*/
+}
+
 void TitleWidget::rectChanged() {
     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
     if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) {
index 02e4a463587cb0da889acaefb0377f766ea42cf8..59b0f8205c3729561384f7c401264b5371fce13f 100644 (file)
@@ -78,6 +78,7 @@ private slots:
     void slotZoom(bool up);
     void slotAdjustZoom();
     void slotZoomOneToOne();
+    void slotUpdateText();
 };
 
 
index 5caa8a96f29c5d33050e987a86564ed7e1a1a728..ce90114ff22ab7d1769a24be0dd0e7b3f0b16342 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>794</width>
-    <height>598</height>
+    <width>771</width>
+    <height>510</height>
    </rect>
   </property>
   <property name="sizePolicy" >
@@ -18,8 +18,8 @@
   <property name="windowTitle" >
    <string>Dialog</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout_2" >
-   <item row="0" column="0" colspan="6" >
+  <layout class="QGridLayout" name="gridLayout_4" >
+   <item row="0" column="0" colspan="5" >
     <layout class="QHBoxLayout" >
      <item>
       <widget class="QPushButton" name="newRectButton" >
@@ -71,7 +71,7 @@
      </item>
     </layout>
    </item>
-   <item row="1" column="0" colspan="6" >
+   <item row="1" column="0" colspan="5" >
     <widget class="QFrame" name="frame_properties" >
      <property name="frameShape" >
       <enum>QFrame::StyledPanel</enum>
        </layout>
       </item>
      </layout>
+     <zorder>splitter</zorder>
     </widget>
    </item>
-   <item row="2" column="0" colspan="6" >
+   <item row="2" column="0" colspan="5" >
     <widget class="QSplitter" name="splitter" >
      <property name="sizePolicy" >
       <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
      <widget class="QGraphicsView" name="graphicsView" />
      <widget class="QToolBox" name="toolBox" >
       <property name="currentIndex" >
-       <number>3</number>
+       <number>2</number>
       </property>
       <widget class="QWidget" name="BasicOperations" >
        <property name="geometry" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>287</width>
-         <height>265</height>
+         <width>297</width>
+         <height>185</height>
         </rect>
        </property>
        <attribute name="label" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>287</width>
-         <height>265</height>
+         <width>297</width>
+         <height>185</height>
         </rect>
        </property>
        <attribute name="label" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>358</width>
-         <height>246</height>
+         <width>267</width>
+         <height>177</height>
         </rect>
        </property>
        <attribute name="label" >
         <string>Text</string>
        </attribute>
-       <layout class="QGridLayout" >
+       <layout class="QGridLayout" name="gridLayout_2" >
         <item row="0" column="0" >
-         <layout class="QVBoxLayout" >
+         <widget class="QFontComboBox" name="font_family" />
+        </item>
+        <item row="1" column="0" >
+         <layout class="QHBoxLayout" name="horizontalLayout" >
           <item>
-           <layout class="QHBoxLayout" >
-            <item>
-             <widget class="QToolButton" name="toolButton_4" >
-              <property name="text" >
-               <string>...</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QToolButton" name="toolButton_5" >
-              <property name="text" >
-               <string>...</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QToolButton" name="toolButton_6" >
-              <property name="text" >
-               <string>...</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="KColorButton" name="fontColorButton" />
-            </item>
-            <item>
-             <widget class="QSlider" name="textAlpha" >
-              <property name="orientation" >
-               <enum>Qt::Horizontal</enum>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <spacer>
-              <property name="orientation" >
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0" >
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-           </layout>
+           <widget class="QSpinBox" name="font_size" >
+            <property name="minimum" >
+             <number>8</number>
+            </property>
+            <property name="maximum" >
+             <number>1000</number>
+            </property>
+            <property name="value" >
+             <number>20</number>
+            </property>
+           </widget>
           </item>
           <item>
-           <layout class="QHBoxLayout" >
-            <item>
-             <widget class="QToolButton" name="toolButton" >
-              <property name="text" >
-               <string>...</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QToolButton" name="fontBold" >
-              <property name="text" >
-               <string>...</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="QToolButton" name="toolButton_3" >
-              <property name="text" >
-               <string>...</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <spacer>
-              <property name="orientation" >
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0" >
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-           </layout>
+           <widget class="KColorButton" name="fontColorButton" />
           </item>
           <item>
-           <widget class="KFontRequester" name="kfontrequester" >
-            <property name="font" >
-             <font>
-              <family>Sans Serif</family>
-              <pointsize>20</pointsize>
-              <weight>50</weight>
-              <italic>false</italic>
-              <bold>false</bold>
-             </font>
+           <widget class="QSlider" name="textAlpha" >
+            <property name="maximum" >
+             <number>255</number>
+            </property>
+            <property name="value" >
+             <number>255</number>
+            </property>
+            <property name="orientation" >
+             <enum>Qt::Horizontal</enum>
             </property>
            </widget>
           </item>
+         </layout>
+        </item>
+        <item row="2" column="0" >
+         <layout class="QHBoxLayout" name="horizontalLayout_2" >
           <item>
-           <widget class="KTextEdit" name="ktextedit" />
+           <widget class="QToolButton" name="toolButton_6" >
+            <property name="text" >
+             <string>...</string>
+            </property>
+           </widget>
           </item>
           <item>
-           <spacer>
-            <property name="orientation" >
-             <enum>Qt::Vertical</enum>
+           <widget class="QToolButton" name="toolButton_5" >
+            <property name="text" >
+             <string>...</string>
             </property>
-            <property name="sizeType" >
-             <enum>QSizePolicy::Expanding</enum>
+           </widget>
+          </item>
+          <item>
+           <widget class="QToolButton" name="toolButton_4" >
+            <property name="text" >
+             <string>...</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QToolButton" name="toolButton_7" >
+            <property name="text" >
+             <string>...</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QToolButton" name="toolButton_8" >
+            <property name="text" >
+             <string>...</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QToolButton" name="toolButton_9" >
+            <property name="text" >
+             <string>...</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer_2" >
+            <property name="orientation" >
+             <enum>Qt::Horizontal</enum>
             </property>
             <property name="sizeHint" stdset="0" >
              <size>
-              <width>20</width>
-              <height>40</height>
+              <width>52</width>
+              <height>20</height>
              </size>
             </property>
            </spacer>
           </item>
          </layout>
         </item>
+        <item row="3" column="0" >
+         <widget class="KTextEdit" name="ktextedit" />
+        </item>
        </layout>
       </widget>
       <widget class="QWidget" name="Rectangle" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>287</width>
-         <height>265</height>
+         <width>278</width>
+         <height>249</height>
         </rect>
        </property>
        <attribute name="label" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>287</width>
-         <height>265</height>
+         <width>297</width>
+         <height>185</height>
         </rect>
        </property>
        <attribute name="label" >
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>287</width>
-         <height>265</height>
+         <width>278</width>
+         <height>224</height>
         </rect>
        </property>
        <attribute name="label" >
     </widget>
    </item>
    <item row="3" column="4" >
-    <spacer name="horizontalSpacer_2" >
-     <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="sizeHint" stdset="0" >
-      <size>
-       <width>387</width>
-       <height>20</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-   <item row="3" column="5" >
     <widget class="QDialogButtonBox" name="buttonBox" >
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>
    <extends>QPushButton</extends>
    <header>kcolorbutton.h</header>
   </customwidget>
-  <customwidget>
-   <class>KFontRequester</class>
-   <extends>QWidget</extends>
-   <header>kfontrequester.h</header>
-  </customwidget>
   <customwidget>
    <class>KIntSpinBox</class>
    <extends>QSpinBox</extends>
     </hint>
    </hints>
   </connection>
-  <connection>
-   <sender>kfontrequester</sender>
-   <signal>fontSelected(QFont)</signal>
-   <receiver>ktextedit</receiver>
-   <slot>setCurrentFont(QFont)</slot>
-   <hints>
-    <hint type="sourcelabel" >
-     <x>715</x>
-     <y>184</y>
-    </hint>
-    <hint type="destinationlabel" >
-     <x>713</x>
-     <y>240</y>
-    </hint>
-   </hints>
-  </connection>
   <connection>
    <sender>fontColorButton</sender>
    <signal>changed(QColor)</signal>