]> git.sesse.net Git - kdenlive/commitdiff
Effect stack: mouse wheel changes parameter when no scrolling is possible
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 26 Mar 2012 12:19:07 +0000 (14:19 +0200)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 26 Mar 2012 12:19:07 +0000 (14:19 +0200)
src/customtrackview.cpp
src/effectstack/collapsibleeffect.cpp
src/effectstack/collapsibleeffect.h
src/effectstack/effectstackview2.cpp
src/effectstack/effectstackview2.h
src/mainwindow.cpp

index 58a2d1b1d1ac3ac7947c69f7eff40b1b73eedc79..e60c83659086fff1b5ec368810e1eb5a89dbe3aa 100644 (file)
@@ -1842,7 +1842,7 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
                        clip->setSelected(true);
                    }
                    clip->setSelectedEffect(clip->effectsCount() - 1);
-                   emit clipItemSelected(clip, clip->selectedEffectIndex());
+                   //emit clipItemSelected(clip, clip->selectedEffectIndex());
                    break;
                }
            }
index 5e459c2990f810302609f689cce7ffeab796ec97..4d49f10d9e9fbbd882fc350d91a4581891e5e6fe 100644 (file)
@@ -128,6 +128,7 @@ CollapsibleEffect::CollapsibleEffect(QDomElement effect, QDomElement original_ef
 {
     //setMouseTracking(true);
     setupUi(this);
+    filterWheelEvent = true;
     m_info.fromString(effect.attribute("kdenlive_info"));
     frame->setBackgroundRole(QPalette::Midlight);
     frame->setAutoFillBackground(true);
@@ -225,7 +226,7 @@ bool CollapsibleEffect::eventFilter( QObject * o, QEvent * e )
 {
     if (e->type() == QEvent::Wheel) {
        QWheelEvent *we = static_cast<QWheelEvent *>(e);
-       if (we->modifiers() != Qt::NoModifier) {
+       if (!filterWheelEvent || we->modifiers() != Qt::NoModifier) {
            e->accept();
            return false;
        }
@@ -274,6 +275,11 @@ QDomElement CollapsibleEffect::effect() const
     return m_effect;
 }
 
+bool CollapsibleEffect::isActive() const
+{
+    return m_active;
+}
+
 void CollapsibleEffect::setActive(bool activate, bool focused)
 {
     m_active = activate;
@@ -314,6 +320,9 @@ void CollapsibleEffect::leaveEvent ( QEvent * event )
 void CollapsibleEffect::slotEnable(bool enable)
 {
     title->setEnabled(enable);
+    enabledBox->blockSignals(true);
+    enabledBox->setChecked(enable);
+    enabledBox->blockSignals(false);
     if (m_isGroup) {
        QVBoxLayout *vbox = static_cast<QVBoxLayout *>(widgetFrame->layout());
        if (vbox == NULL) return;
index 5b7df1cb1e35ad7edec5e885c5d86ea2a80819e0..d58cd5558ab5a58d543e2606e46cc4df77e49f61 100644 (file)
@@ -131,13 +131,16 @@ public:
     void setGroupIndex(int ix);
     void removeGroup(int ix, QVBoxLayout *layout);
     QString infoString() const;
+    bool isActive() const;
+    /** @brief Should the wheel event be sent to parent widget for scrolling. */
+    bool filterWheelEvent;
 
 public slots:
     void slotSyncEffectsPos(int pos);
+    void slotEnable(bool enable);
 
 private slots:
     void slotSwitch();
-    void slotEnable(bool enable);
     void slotShow(bool show);
     void slotDeleteEffect();
     void slotEffectUp();
index 4aa4d4ef66404278b843d6871c92efcb939edc0a..c65e15656dbde5f8e1025cc422b77fcacdbe7327 100644 (file)
@@ -38,6 +38,7 @@
 #include <QTextStream>
 #include <QFile>
 #include <QInputDialog>
+#include <QScrollBar>
 
 
 EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
@@ -56,6 +57,8 @@ EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
     m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
     m_ui.buttonShowComments->setIcon(KIcon("help-about"));
     m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
+    
+    connect(m_ui.checkAll, SIGNAL(stateChanged(int)), this, SLOT(slotCheckAll(int)));
 
 
     setEnabled(false);
@@ -91,11 +94,6 @@ void EffectStackView2::slotRenderPos(int pos)
         m_effects.at(i)->slotSyncEffectsPos(pos);
 }
 
-void EffectStackView2::setMenu(QMenu *menu)
-{
-    //m_ui.buttonNew->setMenu(menu);
-}
-
 void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
 {
     if (c && !c->isEnabled()) return;
@@ -113,6 +111,7 @@ void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
                 m_ui.checkAll->setToolTip(QString());
                 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
             }
+            m_ui.checkAll->setEnabled(true);
             ix = c->selectedEffectIndex();
             QString size = c->baseClip()->getProperty("frame_size");
             double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
@@ -150,8 +149,6 @@ void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
 
 void EffectStackView2::setupListView(int ix)
 {
-    //TODO: clear list
-
     blockSignals(true);
     m_draggedEffect = NULL;
     disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
@@ -164,6 +161,7 @@ void EffectStackView2::setupListView(int ix)
     blockSignals(false);
     view = new QWidget(m_ui.container);
     m_ui.container->setWidget(view);
+    slotUpdateCheckAllButton();
 
     QVBoxLayout *vbox1 = new QVBoxLayout(view);
     vbox1->setContentsMargins(0, 0, 0, 0);
@@ -180,10 +178,9 @@ void EffectStackView2::setupListView(int ix)
        EffectInfo effectInfo;
        effectInfo.fromString(d.attribute("kdenlive_info"));
        if (effectInfo.groupIndex >= 0) {
-           for (int j = 0; j < vbox1->count(); j++) {
-               CollapsibleEffect *gp = static_cast<CollapsibleEffect *>(vbox1->itemAt(j)->widget());
-               if (gp->groupIndex() == effectInfo.groupIndex) {
-                   group = gp;
+           for (int i = 0; i < m_effects.count(); i++) {
+               if (m_effects.at(i)->groupIndex() == effectInfo.groupIndex) {
+                   group = m_effects.at(i);
                    break;
                }
            }
@@ -242,6 +239,30 @@ void EffectStackView2::setupListView(int ix)
     }
     vbox1->addStretch(10);
     connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
+    
+    // Wait a little bit for the new layout to be ready, then check if we have a scrollbar
+    QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
+}
+
+
+void EffectStackView2::slotCheckWheelEventFilter()
+{
+    // If the effect stack widget has no scrollbar, we will not filter the
+    // mouse wheel events, so that user can easily adjust effect params
+    bool filterWheelEvent = false;
+    if (m_ui.container->verticalScrollBar() && m_ui.container->verticalScrollBar()->isVisible()) {
+       // widget has scroll bar, 
+       filterWheelEvent = true;
+    }
+    for (int i = 0; i < m_effects.count(); i++) {
+       m_effects.at(i)->filterWheelEvent = filterWheelEvent;
+    }    
+}
+
+void EffectStackView2::resizeEvent ( QResizeEvent * event )
+{
+    slotCheckWheelEventFilter();
+    QWidget::resizeEvent(event);
 }
 
 bool EffectStackView2::eventFilter( QObject * o, QEvent * e ) 
@@ -317,6 +338,7 @@ void EffectStackView2::slotUpdateEffectState(bool disable, int index)
         emit changeEffectState(NULL, m_trackindex, index, disable);
     else
         emit changeEffectState(m_clipref, -1, index, disable);
+    slotUpdateCheckAllButton();
 }
 
 
@@ -367,18 +389,61 @@ void EffectStackView2::clear()
     }
     m_ui.checkAll->setToolTip(QString());
     m_ui.checkAll->setText(QString());
+    m_ui.checkAll->setEnabled(false);
     setEnabled(false);
 }
 
-void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
+void EffectStackView2::slotCheckAll(int state)
 {
-    m_effectMetaInfo.profile = profile;
-    m_effectMetaInfo.timecode = t;
+    if (state == 1) {
+        state = 2;
+        m_ui.checkAll->blockSignals(true);
+        m_ui.checkAll->setCheckState(Qt::Checked);
+        m_ui.checkAll->blockSignals(false);
+    }
+
+    bool disabled = (state != 2);
+    for (int i = 0; i < m_effects.count(); i++) {
+       if (m_effects.at(i)->groupIndex() == -1) {
+           m_effects.at(i)->slotEnable(disabled);
+       }
+    }
 }
 
-void EffectStackView2::slotItemDel()
+void EffectStackView2::slotUpdateCheckAllButton()
 {
+    bool hasEnabled = false;
+    bool hasDisabled = false;
+    
+    for (int i = 0; i < m_effects.count(); i++) {
+       if (m_effects.at(i)->enabledBox->isChecked()) hasEnabled = true;
+       else hasDisabled = true; 
+    }
 
+    m_ui.checkAll->blockSignals(true);
+    if (hasEnabled && hasDisabled)
+        m_ui.checkAll->setCheckState(Qt::PartiallyChecked);
+    else if (hasEnabled)
+        m_ui.checkAll->setCheckState(Qt::Checked);
+    else
+        m_ui.checkAll->setCheckState(Qt::Unchecked);
+    m_ui.checkAll->blockSignals(false);
+}
+
+void EffectStackView2::deleteCurrentEffect()
+{
+    for (int i = 0; i < m_effects.count(); i++) {
+        if (m_effects.at(i)->isActive()) {
+           slotDeleteEffect(m_effects.at(i)->effect());
+           break;
+       }
+    }
+}
+
+void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
+{
+    m_effectMetaInfo.profile = profile;
+    m_effectMetaInfo.timecode = t;
 }
 
 void EffectStackView2::updateTimecodeFormat()
@@ -406,6 +471,7 @@ void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomE
         // Make sure the changed effect is currently displayed
         slotSetCurrentEffect(ix);
     }
+    QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
 }
 
 void EffectStackView2::slotSetCurrentEffect(int ix)
@@ -515,14 +581,12 @@ void EffectStackView2::slotCreateGroup(int ix)
     
     QVBoxLayout *l = static_cast<QVBoxLayout *>(m_ui.container->widget()->layout());
     int groupPos = 0;
-    
     CollapsibleEffect *effectToMove = NULL;
-    for (int j = 0; j < l->count(); j++) {
-       CollapsibleEffect *gp = static_cast<CollapsibleEffect *>(l->itemAt(j)->widget());
-       if (gp->effectIndex() == ix) {
-           effectToMove = gp;
-           groupPos = l->indexOf(gp);
-           l->removeWidget(gp);
+    for (int i = 0; i < m_effects.count(); i++) {
+        if (m_effects.at(i)->effectIndex() == ix) {
+           effectToMove = m_effects.at(i);
+           groupPos = l->indexOf(effectToMove);
+           l->removeWidget(effectToMove);
            break;
        }
     }
index 2f7a6ba3aa349dff1e6b680a26faed498359fa6c..ae966bb77a2ab7698a571b1fa39b3c64667b50fd 100644 (file)
@@ -45,10 +45,6 @@ public:
     /** @brief Raises @param dock if a clip is loaded. */
     void raiseWindow(QWidget* dock);
 
-    /** @brief Sets the add effect button's menu to @param menu. */
-    void setMenu(QMenu *menu);
-
-
     /** @brief return the index of the track displayed in effect stack
      ** @param ok set to true if we are looking at a track's effects, otherwise false. */
     int isTrackMode(bool *ok) const;
@@ -66,10 +62,14 @@ public:
     virtual bool eventFilter( QObject * o, QEvent * e );
     
     CollapsibleEffect *getEffectByIndex(int ix);
+    
+    /** @brief Delete currently selected effect. */
+    void deleteCurrentEffect();
 
 protected:
     virtual void mouseMoveEvent(QMouseEvent * event);
     virtual void mouseReleaseEvent(QMouseEvent * event);
+    virtual void resizeEvent ( QResizeEvent * event );
   
 private:
     Ui::EffectStack2_UI m_ui;
@@ -109,9 +109,9 @@ public slots:
     void slotClipItemSelected(ClipItem* c, int ix);
 
     void slotTrackItemSelected(int ix, const TrackInfo info);
-
-    /** @brief Removes the selected effect. */
-    void slotItemDel();
+   
+    /** @brief Check if the mouse wheel events should be used for scrolling the widget view. */
+    void slotCheckWheelEventFilter();
 
 private slots:
 
@@ -162,7 +162,14 @@ private slots:
     /** @brief Remove effects from a group */
     void slotUnGroup(CollapsibleEffect* group);
     
+    /** @brief Add en effect to selected clip */
     void slotAddEffect(QDomElement effect);
+    
+    /** @brief Enable / disable all effects for the clip */
+    void slotCheckAll(int state);
+    
+    /** @brief Update check all button status */
+    void slotUpdateCheckAllButton();
 
 signals:
     void removeEffect(ClipItem*, int, QDomElement);
index 5f6db6c71e9267762cc7ecfa60e49dcdb4890cd5..6e48f3db0486d4bb8c5bd75b228a2fcdfda086e9 100644 (file)
@@ -520,8 +520,6 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     connect(m_effectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
     connect(m_transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
 
-    m_effectStack->setMenu(m_effectsMenu);
-
     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
     const QList<QAction *> viewActions = createPopupMenu()->actions();
     viewMenu->insertActions(NULL, viewActions);
@@ -2741,7 +2739,7 @@ void MainWindow::slotDeleteItem()
         QWidget *widget = QApplication::focusWidget();
         while (widget) {
             if (widget == m_effectStackDock) {
-                m_effectStack->slotItemDel();
+                m_effectStack->deleteCurrentEffect();
                 return;
             }
             widget = widget->parentWidget();