Commit cd5949f3 authored by Nicolas Carion's avatar Nicolas Carion

Move DraggableLabel in its own class and add base class to DoubleParameterWidget

parent c129ceb9
......@@ -14,11 +14,13 @@ set(kdenlive_SRCS
effectstack/animkeyframeruler.cpp
effectstack/parametercontainer.cpp
effectstack/positionedit.cpp
effectstack/widgets/abstractparamwidget.h
effectstack/widgets/animationwidget.cpp
effectstack/widgets/choosecolorwidget.cpp
effectstack/widgets/colorpickerwidget.cpp
effectstack/widgets/cornerswidget.cpp
effectstack/widgets/doubleparameterwidget.cpp
effectstack/widgets/draggablelabel.cpp
effectstack/widgets/geometrywidget.cpp
effectstack/widgets/kis_cubic_curve.cpp
effectstack/widgets/kis_curve_widget.cpp
......
......@@ -29,9 +29,10 @@
#include "widgets/doubleparameterwidget.h"
#include "widgets/cornerswidget.h"
#include "widgets/bezier/beziersplinewidget.h"
#include "effectstack/widgets/lumaliftgain.h"
#include "effectstack/widgets/animationwidget.h"
#include "effectstack/widgets/selectivecolor.h"
#include "widgets/lumaliftgain.h"
#include "widgets/animationwidget.h"
#include "widgets/selectivecolor.h"
#include "widgets/draggablelabel.h"
#include "kdenlivesettings.h"
#include "mainwindow.h"
......@@ -59,47 +60,6 @@
#include <QDrag>
#include <QMimeData>
DraggableLabel::DraggableLabel(const QString &text, QWidget *parent):
QLabel(text, parent)
, m_dragStarted(false)
{
setContextMenuPolicy(Qt::NoContextMenu);
setToolTip(i18n("Click to copy data to clipboard"));
}
void DraggableLabel::mousePressEvent(QMouseEvent *ev)
{
QLabel::mousePressEvent(ev);
if (ev->button() == Qt::LeftButton) {
m_clickStart = ev->pos();
m_dragStarted = false;
}
}
void DraggableLabel::mouseReleaseEvent(QMouseEvent *ev)
{
// Don't call mouserelease in cas of drag because label might be deleted by a drop
if (!m_dragStarted) {
QLabel::mouseReleaseEvent(ev);
} else {
ev->ignore();
}
m_clickStart = QPoint();
}
void DraggableLabel::mouseMoveEvent(QMouseEvent *ev)
{
if (m_dragStarted) {
ev->ignore();
return;
}
QLabel::mouseMoveEvent(ev);
if (!m_clickStart.isNull() && (m_clickStart - ev->pos()).manhattanLength() >= QApplication::startDragDistance()) {
emit startDrag(objectName());
m_dragStarted = true;
m_clickStart = QPoint();
}
}
MySpinBox::MySpinBox(QWidget *parent):
QSpinBox(parent)
......
......@@ -27,6 +27,7 @@
class GeometryWidget;
class AnimationWidget;
class Monitor;
class DraggableLabel;
namespace Mlt
{
......@@ -56,22 +57,6 @@ struct wipeInfo {
int endTransparency;
};
class DraggableLabel : public QLabel
{
Q_OBJECT
public:
explicit DraggableLabel(const QString &text, QWidget *parent = Q_NULLPTR);
protected:
void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
signals:
void startDrag(const QString &);
private:
QPoint m_clickStart;
bool m_dragStarted;
};
class MySpinBox : public QSpinBox
{
Q_OBJECT
......
/***************************************************************************
* Copyright (C) 2016 by Nicolas Carion *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef ABSTRACTPARAMWIDGET_H
#define ABSTRACTPARAMWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QPoint>
#include <QDebug>
/** @brief Base class of all the widgets representing a parameter of an effect
*/
class AbstractParamWidget : public QWidget
{
Q_OBJECT
public:
AbstractParamWidget() = delete;
AbstractParamWidget(QWidget* w):QWidget(w){}
virtual ~AbstractParamWidget(){};
/** @brief Factory method to construct a parameter widget given its xml representation
@param content XML representation of the widget
@param parent Optional parent of the widget
TODO
*/
//static AbstractParamWidget* construct(const QDomElement& content, QWidget* parent = nullptr);
signals:
/** @brief Signal sent when the parameters hold by the widgets are modified
*/
void valueChanged();
public slots:
/** @brief Toggle the comments on or off
*/
void slotShowComment(bool){
qDebug()<<"DEBUG: show comment not correctly overriden";
};
};
#endif
......@@ -24,7 +24,7 @@
#include <QRadioButton>
DoubleParameterWidget::DoubleParameterWidget(const QString &name, double value, double min, double max, double defaultValue, const QString &comment, int id, const QString &suffix, int decimals, bool showRadiobutton, QWidget *parent)
: QWidget(parent)
: AbstractParamWidget(parent)
, factor(1)
, m_radio(Q_NULLPTR)
{
......@@ -47,6 +47,10 @@ DoubleParameterWidget::DoubleParameterWidget(const QString &name, double value,
m_dragVal->setValue(value, false);
connect(m_dragVal, &DragValue::valueChanged, this, &DoubleParameterWidget::slotSetValue);
connect(m_dragVal, &DragValue::inTimeline, this, &DoubleParameterWidget::setInTimeline);
connect(this, &DoubleParameterWidget::valueChanged,
[this](double){ emit qobject_cast<AbstractParamWidget*>(this)->valueChanged();});
}
bool DoubleParameterWidget::hasEditFocus() const
......
......@@ -21,6 +21,7 @@
#define DOUBLEPARAMETERWIDGET_H
#include <QWidget>
#include "abstractparamwidget.h"
class DragValue;
class QRadioButton;
......@@ -33,7 +34,7 @@ class QRadioButton;
* The widget does only handle integers, so the parameter has to be converted into the proper double range afterwards.
*/
class DoubleParameterWidget : public QWidget
class DoubleParameterWidget : public AbstractParamWidget
{
Q_OBJECT
public:
......
/***************************************************************************
* Copyright (C) 2016 by Nicolas Carion *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "draggablelabel.h"
#include <QMouseEvent>
#include <QApplication>
#include "klocalizedstring.h"
DraggableLabel::DraggableLabel(const QString &text, QWidget *parent):
QLabel(text, parent)
, m_dragStarted(false)
{
setContextMenuPolicy(Qt::NoContextMenu);
setToolTip(i18n("Click to copy data to clipboard"));
}
void DraggableLabel::mousePressEvent(QMouseEvent *ev)
{
QLabel::mousePressEvent(ev);
if (ev->button() == Qt::LeftButton) {
m_clickStart = ev->pos();
m_dragStarted = false;
}
}
void DraggableLabel::mouseReleaseEvent(QMouseEvent *ev)
{
// Don't call mouserelease in cas of drag because label might be deleted by a drop
if (!m_dragStarted)
QLabel::mouseReleaseEvent(ev);
else
ev->ignore();
m_clickStart = QPoint();
}
void DraggableLabel::mouseMoveEvent(QMouseEvent *ev)
{
if (m_dragStarted) {
ev->ignore();
return;
}
QLabel::mouseMoveEvent(ev);
if (!m_clickStart.isNull() && (m_clickStart - ev->pos()).manhattanLength() >= QApplication::startDragDistance()) {
emit startDrag(objectName());
m_dragStarted = true;
m_clickStart = QPoint();
}
}
/***************************************************************************
* Copyright (C) 2016 by Nicolas Carion *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef DRAGGABLELABEL_H
#define DRAGGABLELABEL_H
#include <QWidget>
#include <QLabel>
#include <QPoint>
class DraggableLabel : public QLabel
{
Q_OBJECT
public:
explicit DraggableLabel(const QString &text, QWidget *parent = Q_NULLPTR);
protected:
void mousePressEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void mouseMoveEvent(QMouseEvent *ev);
signals:
void startDrag(const QString &);
private:
QPoint m_clickStart;
bool m_dragStarted;
};
#endif
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