Cleanup

parent c3ff6415
......@@ -106,8 +106,6 @@ add_subdirectory(effectstack)
add_subdirectory(lib)
add_subdirectory(mltcontroller)
add_subdirectory(monitor)
add_subdirectory(onmonitoritems)
add_subdirectory(onmonitoritems/rotoscoping)
add_subdirectory(profiles)
add_subdirectory(project)
add_subdirectory(qml)
......
......@@ -3319,8 +3319,8 @@ void MainWindow::buildDynamicActions()
actionCollection()->addAction(showTimeline->text(), showTimeline);
QList<QDockWidget *> docks = findChildren<QDockWidget *>();
for (int i = 0; i < docks.count(); ++i) {
QDockWidget *dock = docks.at(i);
for (int j = 0; j < docks.count(); ++j) {
QDockWidget *dock = docks.at(j);
QAction *dockInformations = dock->toggleViewAction();
if (!dockInformations) {
continue;
......
set(kdenlive_SRCS
${kdenlive_SRCS}
onmonitoritems/onmonitorcornersitem.cpp
onmonitoritems/onmonitorrectitem.cpp
onmonitoritems/onmonitorpathitem.cpp
PARENT_SCOPE)
/***************************************************************************
* Copyright (C) 2010 by Till Theato (root@ttill.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. *
* *
* 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 "onmonitorcornersitem.h"
#include "kdenlivesettings.h"
#include <algorithm>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
OnMonitorCornersItem::OnMonitorCornersItem(QGraphicsItem *parent)
: QGraphicsPolygonItem(parent)
, m_mode(NoAction)
, m_selectedCorner(-1)
, m_modified(false)
, m_view(nullptr)
{
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
QPen framepen(Qt::SolidLine);
framepen.setColor(Qt::yellow);
setPen(framepen);
setBrush(Qt::NoBrush);
setAcceptHoverEvents(true);
}
OnMonitorCornersItem::cornersActions OnMonitorCornersItem::getMode(const QPointF &pos, int *corner)
{
*corner = -1;
if (polygon().count() != 4) {
return NoAction;
}
QPainterPath mouseArea;
qreal size = 12;
if (getView()) {
size /= m_view->matrix().m11();
}
mouseArea.addRect(pos.x() - size / 2, pos.y() - size / 2, size, size);
for (int i = 0; i < 4; ++i) {
if (mouseArea.contains(polygon().at(i))) {
*corner = i;
return Corner;
}
}
if (KdenliveSettings::onmonitoreffects_cornersshowcontrols()) {
if (mouseArea.contains(getCentroid())) {
return Move;
}
for (int i = 0; i < 4; ++i) {
int j = (i + 1) % 4;
if (mouseArea.contains(QLineF(polygon().at(i), polygon().at(j)).pointAt(.5))) {
*corner = i;
return MoveSide;
}
}
}
return NoAction;
}
void OnMonitorCornersItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
m_mode = getMode(event->pos(), &m_selectedCorner);
m_lastPoint = event->scenePos();
if (m_mode == NoAction) {
event->ignore();
}
}
void OnMonitorCornersItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
/*if (event->buttons() != Qt::NoButton && (event->screenPos() - m_screenClickPoint).manhattanLength() < QApplication::startDragDistance()) {
* event->accept();
* return;
}*/
if ((event->buttons() & Qt::LeftButton) != 0u) {
QPointF mousePos = mapFromScene(event->scenePos());
QPolygonF p = polygon();
switch (m_mode) {
case Corner:
p.replace(m_selectedCorner, mousePos);
m_modified = true;
break;
case Move:
p.translate(mousePos - m_lastPoint);
m_modified = true;
break;
case MoveSide:
p[m_selectedCorner] += mousePos - m_lastPoint;
p[(m_selectedCorner + 1) % 4] += mousePos - m_lastPoint;
m_modified = true;
break;
default:
break;
}
m_lastPoint = mousePos;
setPolygon(p);
}
if (m_modified) {
event->accept();
if (KdenliveSettings::monitorscene_directupdate()) {
emit changed();
m_modified = false;
}
} else {
event->ignore();
}
}
void OnMonitorCornersItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (m_modified) {
m_modified = false;
emit changed();
}
event->accept();
}
void OnMonitorCornersItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
int corner;
switch (getMode(event->pos(), &corner)) {
case NoAction:
unsetCursor();
break;
case Move:
setCursor(QCursor(Qt::SizeAllCursor));
break;
default:
setCursor(QCursor(Qt::OpenHandCursor));
break;
}
}
void OnMonitorCornersItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QPen(Qt::yellow, 1, Qt::SolidLine));
if (KdenliveSettings::onmonitoreffects_cornersshowlines()) {
QGraphicsPolygonItem::paint(painter, option, widget);
}
if (polygon().count() != 4) {
return;
}
double baseSize = 1 / painter->worldTransform().m11();
painter->setRenderHint(QPainter::Antialiasing);
painter->setBrush(QBrush(isEnabled() ? Qt::yellow : Qt::red));
double handleSize = 4 * baseSize;
for (int i = 0; i < 4; ++i) {
painter->drawEllipse(polygon().at(i), handleSize, handleSize);
}
if (KdenliveSettings::onmonitoreffects_cornersshowcontrols() && isEnabled()) {
painter->setPen(QPen(Qt::red, 2, Qt::SolidLine));
double toolSize = 6 * baseSize;
// move tool
QPointF c = getCentroid();
painter->drawLine(QLineF(c - QPointF(toolSize, toolSize), c + QPointF(toolSize, toolSize)));
painter->drawLine(QLineF(c - QPointF(-toolSize, toolSize), c + QPointF(-toolSize, toolSize)));
// move side tools (2 corners at once)
for (int i = 0; i < 4; ++i) {
int j = (i + 1) % 4;
QPointF m = QLineF(polygon().at(i), polygon().at(j)).pointAt(.5);
painter->drawRect(QRectF(-toolSize / 2., -toolSize / 2., toolSize, toolSize).translated(m));
}
}
}
QPointF OnMonitorCornersItem::getCentroid()
{
QList<QPointF> p = sortedClockwise();
/*
* See: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/
*/
double A = 0;
for (int i = 0; i < 4; ++i) {
int j = (i + 1) % 4;
A += p[j].x() * p[i].y() - p[i].x() * p[j].y();
}
A /= 2.;
A = qAbs(A);
double x = 0, y = 0;
for (int i = 0; i < 4; ++i) {
int j = (i + 1) % 4;
double f = (p[i].x() * p[j].y() - p[j].x() * p[i].y());
x += f * (p[i].x() + p[j].x());
y += f * (p[i].y() + p[j].y());
}
x /= 6 * A;
y /= 6 * A;
return QPointF(x, y);
}
QList<QPointF> OnMonitorCornersItem::sortedClockwise()
{
QList<QPointF> points = polygon().toList();
QPointF &a = points[0];
QPointF &b = points[1];
QPointF &c = points[2];
QPointF &d = points[3];
/*
* http://stackoverflow.com/questions/242404/sort-four-points-in-clockwise-order
*/
double abc = a.x() * b.y() - a.y() * b.x() + b.x() * c.y() - b.y() * c.x() + c.x() * a.y() - c.y() * a.x();
if (abc > 0) {
double acd = a.x() * c.y() - a.y() * c.x() + c.x() * d.y() - c.y() * d.x() + d.x() * a.y() - d.y() * a.x();
if (acd > 0) {
;
} else {
double abd = a.x() * b.y() - a.y() * b.x() + b.x() * d.y() - b.y() * d.x() + d.x() * a.y() - d.y() * a.x();
if (abd > 0) {
std::swap(d, c);
} else {
std::swap(a, d);
}
}
} else {
double acd = a.x() * c.y() - a.y() * c.x() + c.x() * d.y() - c.y() * d.x() + d.x() * a.y() - d.y() * a.x();
if (acd > 0) {
double abd = a.x() * b.y() - a.y() * b.x() + b.x() * d.y() - b.y() * d.x() + d.x() * a.y() - d.y() * a.x();
if (abd > 0) {
std::swap(b, c);
} else {
std::swap(a, b);
}
} else {
std::swap(a, c);
}
}
return points;
}
bool OnMonitorCornersItem::getView()
{
if (m_view) {
return true;
}
if ((scene() != nullptr) && !scene()->views().isEmpty()) {
m_view = scene()->views().first();
return true;
}
return false;
}
/***************************************************************************
* Copyright (C) 2010 by Till Theato (root@ttill.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. *
* *
* 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 ONMONITORCORNERSITEM_H
#define ONMONITORCORNERSITEM_H
#include <QGraphicsPolygonItem>
class QGraphicsView;
class OnMonitorCornersItem : public QObject, public QGraphicsPolygonItem
{
Q_OBJECT
public:
explicit OnMonitorCornersItem(QGraphicsItem *parent = nullptr);
enum cornersActions { Corner, Move, MoveSide, NoAction };
/** @brief Gets The action mode for the area @param pos +- 4. */
cornersActions getMode(const QPointF &pos, int *corner);
/** @brief Reimplemented to draw the handles. */
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
private:
/** @brief Returns the centroid (= 'center of mass') of this polygon. */
QPointF getCentroid();
/** @brief Returns the points of this polygon but sorted clockwise. */
QList<QPointF> sortedClockwise();
/** @brief Tries to get the view of the scene. */
bool getView();
cornersActions m_mode;
/** Number of the selected corner or if in MoveSide mode number of the first corner on this side */
int m_selectedCorner;
QPointF m_lastPoint;
bool m_modified;
QGraphicsView *m_view;
signals:
void changed();
};
#endif
/***************************************************************************
* Copyright (C) 2010 by Till Theato (root@ttill.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. *
* *
* 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 "onmonitorpathitem.h"
#include "kdenlivesettings.h"
#include <QApplication>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <mlt++/Mlt.h>
OnMonitorPathItem::OnMonitorPathItem(QGraphicsItem *parent)
: QGraphicsPathItem(parent)
, m_modified(false)
, m_view(nullptr)
, m_activePoint(-1)
{
setFlags(QGraphicsItem::ItemIsMovable);
QPen framepen(Qt::SolidLine);
framepen.setColor(Qt::red);
setPen(framepen);
setBrush(Qt::transparent);
setAcceptHoverEvents(true);
}
void OnMonitorPathItem::setPoints(Mlt::Geometry *geometry)
{
m_points.clear();
QRectF r;
int pos = 0;
Mlt::GeometryItem item;
while (geometry->next_key(&item, pos) == 0) {
r = QRectF(item.x(), item.y(), item.w(), item.h());
m_points << r.center();
pos = item.frame() + 1;
}
rebuildShape();
}
void OnMonitorPathItem::rebuildShape()
{
if (m_activePoint > m_points.count()) {
m_activePoint = -1;
}
QPainterPath p;
QPainterPath shape;
if (!m_points.isEmpty()) {
QRectF r(0, 0, 20, 20);
r.moveCenter(m_points.at(0));
shape.addRect(r);
p.moveTo(m_points.at(0));
for (int i = 1; i < m_points.count(); ++i) {
p.lineTo(m_points.at(i));
r.moveCenter(m_points.at(i));
shape.addRect(r);
}
}
prepareGeometryChange();
m_shape = shape;
setPath(p);
}
void OnMonitorPathItem::getMode(const QPointF &pos)
{
double dist = 8;
if (getView()) {
dist /= m_view->matrix().m11();
}
// Item mapped coordinates
for (int i = 0; i < m_points.count(); ++i) {
if ((pos - m_points.at(i)).manhattanLength() <= dist) {
m_activePoint = i;
return;
}
}
m_activePoint = -1;
}
void OnMonitorPathItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
/*if (event->buttons() != Qt::NoButton && (event->screenPos() - m_screenClickPoint).manhattanLength() < QApplication::startDragDistance()) {
* event->accept();
* return;
}*/
if (m_activePoint >= 0 && ((event->buttons() & Qt::LeftButton) != 0u)) {
QPointF mousePos = event->pos();
m_points[m_activePoint] = mousePos;
rebuildShape();
m_modified = true;
update();
}
if (m_modified) {
event->accept();
if (KdenliveSettings::monitorscene_directupdate()) {
emit changed();
m_modified = false;
}
} else {
event->ignore();
}
}
QList<QPointF> OnMonitorPathItem::points() const
{
return m_points;
}
void OnMonitorPathItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (m_modified) {
m_modified = false;
emit changed();
}
event->accept();
}
QRectF OnMonitorPathItem::boundingRect() const
{
return shape().boundingRect();
}
QPainterPath OnMonitorPathItem::shape() const
{
return m_shape;
}
void OnMonitorPathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
{
if (m_activePoint != -1) {
m_activePoint = -1;
update();
}
unsetCursor();
}
void OnMonitorPathItem::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
{
setCursor(QCursor(Qt::PointingHandCursor));
}
void OnMonitorPathItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
int currentPoint = m_activePoint;
getMode(event->pos());
if (currentPoint != m_activePoint) {
update();
}
setCursor(QCursor(Qt::PointingHandCursor));
}
void OnMonitorPathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// Q_UNUSED(widget)
QGraphicsPathItem::paint(painter, option, widget);
double w = 6;
double h = 6;
if (getView()) {
w /= m_view->matrix().m11();
h /= m_view->matrix().m22();
}
QRectF handle(0, 0, w, h);
for (int i = 0; i < m_points.count(); ++i) {
handle.moveCenter(m_points.at(i));
painter->fillRect(handle, m_activePoint == i ? Qt::blue : pen().color());
}
}
bool OnMonitorPathItem::getView()
{
if (m_view) {
return true;
}
if ((scene() != nullptr) && !scene()->views().isEmpty()) {
m_view = scene()->views().first();
return true;
}
return false;
}
/***************************************************************************
* Copyright (C) 2010 by Till Theato (root@ttill.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. *
* *
* 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 ONMONITORPATHITEM_H
#define ONMONITORPATHITEM_H
#include <QGraphicsPathItem>
class QGraphicsView;
namespace Mlt {
class Geometry;
}
class OnMonitorPathItem : public QObject, public QGraphicsPathItem
{
Q_OBJECT
public:
explicit OnMonitorPathItem(QGraphicsItem *parent = nullptr);
void setPoints(Mlt::Geometry *geometry);
void getMode(const QPointF &pos);
void rebuildShape();
QList<QPointF> points() const;
QPainterPath shape() const override;
/** @brief Reimplemented to draw the handles. */
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
QRectF boundingRect() const override;
protected:
// virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
private:
QList<QPointF> m_points;
QPointF m_lastPoint;
bool m_modified;
QGraphicsView *m_view;
int m_activePoint;
QPainterPath m_shape;
/** @brief Tries to get the view of the scene. */
bool getView();
signals:
void changed();
};
#endif
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2010 by Till Theato (root@ttill.de) *
* *