Commit e821b2fe authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Fix mouse wheel changing parameters when scrolling in effect stack.

Related to #455
parent beef4bcb
......@@ -41,6 +41,7 @@
#include <QToolButton>
#include <QVBoxLayout>
#include <QScrollArea>
#include <QScrollBar>
#include <QComboBox>
#include <QFontDatabase>
#include <klocalizedstring.h>
......@@ -118,19 +119,20 @@ AssetPanel::AssetPanel(QWidget *parent)
lay->setContentsMargins(0, 0, 0, 0);
lay->addWidget(m_transitionWidget);
lay->addWidget(m_effectStackWidget);
auto *sc = new QScrollArea;
sc->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
sc->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
sc->setFrameStyle(QFrame::NoFrame);
sc->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
m_sc = new QScrollArea;
m_sc->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_sc->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_sc->setFrameStyle(QFrame::NoFrame);
m_sc->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
m_container->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
sc->setWidgetResizable(true);
m_sc->setWidgetResizable(true);
m_lay->addWidget(sc);
sc->setWidget(m_container);
m_lay->addWidget(m_sc);
m_sc->setWidget(m_container);
m_transitionWidget->setVisible(false);
m_effectStackWidget->setVisible(false);
updatePalette();
connect(m_effectStackWidget, &EffectStackView::checkScrollBar, this, &AssetPanel::slotCheckWheelEventFilter);
connect(m_effectStackWidget, &EffectStackView::seekToPos, this, &AssetPanel::seekToPos);
connect(m_effectStackWidget, &EffectStackView::reloadEffect, this, &AssetPanel::reloadEffect);
connect(m_transitionWidget, &TransitionStackView::seekToTransPos, this, &AssetPanel::seekToPos);
......@@ -385,3 +387,15 @@ void AssetPanel::deleteCurrentEffect()
m_effectStackWidget->removeCurrentEffect();
}
}
void AssetPanel::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 blockWheel = false;
if (m_sc->verticalScrollBar() && m_sc->verticalScrollBar()->isVisible()) {
// widget has scroll bar,
blockWheel = true;
}
m_effectStackWidget->blockWheenEvent(blockWheel);
}
......@@ -32,6 +32,7 @@ class KSqueezedTextLabel;
class KDualAction;
class QToolButton;
class QComboBox;
class QScrollArea;
/** @brief This class is the widget that provides interaction with the asset currently selected.
That is, it either displays an effectStack or the parameters of a transition
......@@ -71,6 +72,7 @@ public slots:
/** @brief Clear panel if displaying itemId */
void clearAssetPanel(int itemId);
void deleteCurrentEffect();
void slotCheckWheelEventFilter();
protected:
/** @brief Return the stylesheet used to display the panel (based on current palette). */
......@@ -89,6 +91,7 @@ private:
KDualAction *m_splitButton;
KDualAction *m_enableStackButton;
KDualAction *m_timelineButton;
QScrollArea *m_sc;
private slots:
void processSplitEffect(bool enable);
......
......@@ -227,7 +227,8 @@ void WheelContainer::wheelEvent(QWheelEvent *event)
}
m_color.setValueF(qBound(-m_zeroShift, y, 1. - m_zeroShift));
changeColor(m_color);
} else {
QWidget::wheelEvent(event);
}
}
......
......@@ -21,6 +21,7 @@
#include "collapsibleeffectview.hpp"
#include "assets/view/assetparameterview.hpp"
#include "assets/view/widgets/colorwheel.h"
#include "core.h"
#include "dialogs/clipcreationdialog.h"
#include "effects/effectsrepository.hpp"
......@@ -41,8 +42,9 @@
#include <QStandardPaths>
#include <QVBoxLayout>
#include <QWheelEvent>
#include <QPointer>
#include <KComboBox>
#include <QComboBox>
#include <KDualAction>
#include <KMessageBox>
#include <KRecentDirs>
......@@ -53,6 +55,7 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
, m_view(nullptr)
, m_model(effectModel)
, m_regionEffect(false)
, m_blockWheel(false)
{
QString effectId = effectModel->getAssetId();
QString effectName = i18n(EffectsRepository::get()->getName(effectId).toUtf8().data());
......@@ -60,7 +63,6 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
m_regionEffect = true;
decoframe->setObjectName(QStringLiteral("decoframegroup"));
}
filterWheelEvent = true;
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// decoframe->setProperty("active", true);
// m_info.fromString(effect.attribute(QStringLiteral("kdenlive_info")));
......@@ -198,15 +200,23 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
connect(buttonDown, &QAbstractButton::clicked, this, &CollapsibleEffectView::slotEffectDown);
connect(buttonDel, &QAbstractButton::clicked, this, &CollapsibleEffectView::slotDeleteEffect);
Q_FOREACH (QSpinBox *sp, findChildren<QSpinBox *>()) {
for (QSpinBox *sp : findChildren<QSpinBox *>()) {
sp->installEventFilter(this);
sp->setFocusPolicy(Qt::StrongFocus);
}
Q_FOREACH (KComboBox *cb, findChildren<KComboBox *>()) {
for (QComboBox *cb : findChildren<QComboBox *>()) {
cb->installEventFilter(this);
cb->setFocusPolicy(Qt::StrongFocus);
}
Q_FOREACH (QProgressBar *cb, findChildren<QProgressBar *>()) {
for (QProgressBar *cb : findChildren<QProgressBar *>()) {
cb->installEventFilter(this);
cb->setFocusPolicy(Qt::StrongFocus);
}
for (WheelContainer *cb : findChildren<WheelContainer *>()) {
cb->installEventFilter(this);
cb->setFocusPolicy(Qt::StrongFocus);
}
for (QDoubleSpinBox *cb : findChildren<QDoubleSpinBox *>()) {
cb->installEventFilter(this);
cb->setFocusPolicy(Qt::StrongFocus);
}
......@@ -260,17 +270,20 @@ bool CollapsibleEffectView::eventFilter(QObject *o, QEvent *e)
}
if (e->type() == QEvent::Wheel) {
auto *we = static_cast<QWheelEvent *>(e);
if (!filterWheelEvent || we->modifiers() != Qt::NoModifier) {
if (!m_blockWheel || we->modifiers() != Qt::NoModifier) {
e->accept();
return false;
}
if (qobject_cast<QAbstractSpinBox *>(o)) {
// if (qobject_cast<QAbstractSpinBox *>(o)->focusPolicy() == Qt::WheelFocus) {
if (!qobject_cast<QAbstractSpinBox *>(o)->hasFocus()) {
e->ignore();
return true;
}
e->accept();
return false;
}
if (qobject_cast<KComboBox *>(o)) {
if (qobject_cast<KComboBox *>(o)->focusPolicy() == Qt::WheelFocus) {
if (qobject_cast<QComboBox *>(o)) {
if (qobject_cast<QComboBox *>(o)->focusPolicy() == Qt::WheelFocus) {
e->accept();
return false;
}
......@@ -278,7 +291,18 @@ bool CollapsibleEffectView::eventFilter(QObject *o, QEvent *e)
return true;
}
if (qobject_cast<QProgressBar *>(o)) {
// if (qobject_cast<QProgressBar *>(o)->focusPolicy() == Qt::WheelFocus)*/ {
if (!qobject_cast<QProgressBar *>(o)->hasFocus()) {
e->ignore();
return true;
}
e->accept();
return false;
}
if (qobject_cast<WheelContainer *>(o)) {
if (!qobject_cast<WheelContainer *>(o)->hasFocus()) {
e->ignore();
return true;
}
e->accept();
return false;
}
......@@ -803,3 +827,9 @@ void CollapsibleEffectView::enableView(bool enabled)
widgetFrame->setEnabled(true);
}
}
void CollapsibleEffectView::blockWheenEvent(bool block)
{
m_blockWheel = block;
}
......@@ -69,8 +69,6 @@ public:
QString infoString() const;
bool isActive() const;
bool isEnabled() const;
/** @brief Should the wheel event be sent to parent widget for scrolling. */
bool filterWheelEvent;
/** @brief Show / hide up / down buttons. */
void adjustButtons(int ix, int max);
/** @brief Returns this effect's monitor scene type if any is needed. */
......@@ -91,6 +89,8 @@ public slots:
void importKeyframes(const QString &keyframes);
void slotActivateEffect(QModelIndex ix);
void updateHeight();
/** @brief Should we block wheel event (if parent is a view with scrollbar) */
void blockWheenEvent(bool block);
private slots:
void setWidgetHeight(qreal value);
......@@ -123,6 +123,7 @@ private:
bool m_isMovable;
/** @brief True if this is a region effect, which behaves in a special way, like a group. */
bool m_regionEffect;
bool m_blockWheel;
/** @brief The add group action. */
QAction *m_groupAction;
KDualAction *m_enabledButton;
......
......@@ -36,6 +36,7 @@
#include <QFontDatabase>
#include <QMimeData>
#include <QMutexLocker>
#include <QScrollBar>
#include <QTreeView>
#include <QVBoxLayout>
#include <utility>
......@@ -97,6 +98,11 @@ EffectStackView::EffectStackView(AssetPanel *parent)
m_effectsTree->setVisible(!KdenliveSettings::showbuiltstack());
m_lay->addWidget(m_effectsTree);
m_lay->addStretch(10);
m_scrollTimer.setSingleShot(true);
m_scrollTimer.setInterval(250);
connect(&m_scrollTimer, &QTimer::timeout, this, &EffectStackView::checkScrollBar);
}
EffectStackView::~EffectStackView()
......@@ -164,6 +170,8 @@ void EffectStackView::dropEvent(QDropEvent *event)
}
if (!added) {
pCore->displayMessage(i18n("Cannot add effect to clip"), InformationMessage);
} else {
m_scrollTimer.start();
}
}
}
......@@ -185,6 +193,7 @@ void EffectStackView::setModel(std::shared_ptr<EffectStackModel> model, const QS
m_mutex.unlock();
qDebug() << "MUTEX UNLOCK!!!!!!!!!!!! setmodel";
loadEffects();
m_scrollTimer.start();
connect(m_model.get(), &EffectStackModel::dataChanged, this, &EffectStackView::refresh);
connect(m_model.get(), &EffectStackModel::enabledStateChanged, this, &EffectStackView::updateEnabledState);
connect(this, &EffectStackView::removeCurrentEffect, m_model.get(), &EffectStackModel::removeCurrentEffect);
......@@ -222,6 +231,7 @@ void EffectStackView::loadEffects()
connect(view, &CollapsibleEffectView::startDrag, this, &EffectStackView::slotStartDrag);
connect(view, &CollapsibleEffectView::createGroup, m_model.get(), &EffectStackModel::slotCreateGroup);
connect(view, &CollapsibleEffectView::activateEffect, this, &EffectStackView::slotActivateEffect);
connect(this, &EffectStackView::blockWheenEvent, view, &CollapsibleEffectView::blockWheenEvent);
connect(view, &CollapsibleEffectView::seekToPos, [this](int pos) {
// at this point, the effects returns a pos relative to the clip. We need to convert it to a global time
int clipIn = pCore->getItemPosition(m_model->getOwnerId());
......@@ -259,6 +269,7 @@ void EffectStackView::updateTreeHeight()
}
m_effectsTree->setFixedHeight(totalHeight);
m_mutex.unlock();
m_scrollTimer.start();
}
void EffectStackView::slotActivateEffect(const std::shared_ptr<EffectItemModel> &effectModel)
......@@ -307,6 +318,13 @@ void EffectStackView::slotAdjustDelegate(const std::shared_ptr<EffectItemModel>
}
}
void EffectStackView::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
m_scrollTimer.start();
}
void EffectStackView::refresh(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
Q_UNUSED(roles)
......
......@@ -26,6 +26,7 @@
#include <QMutex>
#include <QStyledItemDelegate>
#include <QWidget>
#include <QTimer>
#include <memory>
class QVBoxLayout;
......@@ -76,6 +77,7 @@ public:
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private:
QMutex m_mutex;
......@@ -85,6 +87,7 @@ private:
std::shared_ptr<EffectStackModel> m_model;
std::vector<CollapsibleEffectView *> m_widgets;
AssetIconProvider *m_thumbnailer;
QTimer m_scrollTimer;
/** @brief the frame size of the original clip this effect is applied on
*/
......@@ -107,6 +110,8 @@ signals:
void reloadEffect(const QString &path);
void updateEnabledState();
void removeCurrentEffect();
void blockWheenEvent(bool block);
void checkScrollBar();
};
#endif
  • Great! And mouse wheel adjusting luma slider with the Shift. Works for me! :)

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment