Commit e0d50496 authored by Laurent Montel's avatar Laurent Montel

Make code more readable

parent 8de5263e
This diff is collapsed.
......@@ -17,7 +17,6 @@
#include <QImage>
class ColorTools : public QObject
{
Q_OBJECT
......@@ -36,7 +35,7 @@ public:
If not the full rect should be filled, set circleOnly to true.
See also: http://en.wikipedia.org/wiki/YUV and http://de.wikipedia.org/wiki/Vektorskop
*/
QImage yuvColorWheel(const QSize& size, const unsigned char &Y, const float &scaling, const bool &modifiedVersion, const bool &circleOnly);
QImage yuvColorWheel(const QSize &size, const unsigned char &Y, const float &scaling, const bool &modifiedVersion, const bool &circleOnly);
/**
@brief Draws a UV plane with given UV angle (ratio u:v stays constant)
scaling defines how far to zoom in (or out). Lower value = zoom in.
......
......@@ -26,7 +26,6 @@ the Free Software Foundation, either version 3 of the License, or
Core *Core::m_self = Q_NULLPTR;
Core::Core(MainWindow *mainWindow) :
m_mainWindow(mainWindow)
, m_projectManager(Q_NULLPTR)
......@@ -50,7 +49,7 @@ Core::~Core()
m_self = 0;
}
void Core::build(MainWindow* mainWindow)
void Core::build(MainWindow *mainWindow)
{
m_self = new Core(mainWindow);
m_self->initLocale();
......@@ -85,13 +84,12 @@ void Core::initialize()
emit coreIsReady();
}
Core* Core::self()
Core *Core::self()
{
return m_self;
}
MainWindow* Core::window()
MainWindow *Core::window()
{
return m_mainWindow;
}
......@@ -101,7 +99,7 @@ ProjectManager *Core::projectManager()
return m_projectManager;
}
MonitorManager* Core::monitorManager()
MonitorManager *Core::monitorManager()
{
return m_monitorManager;
}
......@@ -152,4 +150,3 @@ void Core::initLocale()
QLocale::setDefault(systemLocale);
}
......@@ -24,11 +24,10 @@ class ProducerQueue;
#define pCore Core::self()
/**
* @class Core
* @brief Singleton that provides access to the different parts of Kdenlive
*
*
* Needs to be initialize before any widgets are created in MainWindow.
* Plugins should be loaded after the widget setup.
*/
......
......@@ -33,11 +33,11 @@ QDebug operator << (QDebug qd, const ItemInfo &info)
QDebug operator << (QDebug qd, const MltVideoProfile &profile)
{
qd << "Profile "<< &profile;
qd << "Profile " << &profile;
qd << "\tProfile fps num " << profile.frame_rate_num;
qd << "\tProfile fps den " << profile.frame_rate_den;
qd << "\tProfile width " << profile.width,
qd << "\tProfile height " << profile.height;
qd << "\tProfile height " << profile.height;
qd << "\tProfile progressive " << profile.progressive;
qd << "\tProfile sar num " << profile.sample_aspect_num;
qd << "\tProfile sar den " << profile.sample_aspect_den;
......@@ -48,7 +48,6 @@ QDebug operator << (QDebug qd, const MltVideoProfile &profile)
return qd.maybeSpace();
}
MltVideoProfile::MltVideoProfile() :
frame_rate_num(0),
frame_rate_den(0),
......@@ -102,12 +101,12 @@ bool MltVideoProfile::operator==(const MltVideoProfile &point) const
int sar = sample_aspect_num * 100 / sample_aspect_den;
int dar = display_aspect_num * 100 / display_aspect_den;
return point.frame_rate_num * 100 / point.frame_rate_den == fps &&
point.width == width &&
point.height == height &&
point.progressive == progressive &&
point.sample_aspect_num * 100 / point.sample_aspect_den == sar &&
point.display_aspect_num * 100 / point.display_aspect_den == dar &&
point.colorspace == colorspace;
point.width == width &&
point.height == height &&
point.progressive == progressive &&
point.sample_aspect_num * 100 / point.sample_aspect_den == sar &&
point.display_aspect_num * 100 / point.display_aspect_den == dar &&
point.colorspace == colorspace;
}
bool MltVideoProfile::isCompatible(const MltVideoProfile &point) const
......@@ -120,11 +119,10 @@ bool MltVideoProfile::isValid() const
return (frame_rate_den > 0 && sample_aspect_den > 0 && display_aspect_den > 0 && width > 0);
}
const QVariantList MltVideoProfile::toList() const
{
QVariantList result;
result << frame_rate_num << frame_rate_den << width << height << progressive << sample_aspect_num << sample_aspect_den <<display_aspect_num << display_aspect_den << colorspace << path << description;
result << frame_rate_num << frame_rate_den << width << height << progressive << sample_aspect_num << sample_aspect_den << display_aspect_num << display_aspect_den << colorspace << path << description;
return result;
}
......@@ -136,7 +134,9 @@ void MltVideoProfile::adjustWidth()
const QString MltVideoProfile::descriptiveString()
{
QString data = description;
if (!data.isEmpty()) data.append(QStringLiteral(" "));
if (!data.isEmpty()) {
data.append(QStringLiteral(" "));
}
QString fps;
if (frame_rate_num % frame_rate_den == 0) {
fps = QString::number(frame_rate_num / frame_rate_den);
......@@ -155,38 +155,43 @@ const QString MltVideoProfile::dialogDescriptiveString()
} else {
text = QString::number((double)frame_rate_num / frame_rate_den, 'f', 2);
}
text.append(i18nc("frames per second","fps"));
if (!progressive)
text.append(i18nc("frames per second", "fps"));
if (!progressive) {
text.append(i18n(" interlaced"));
}
return text;
}
bool MltVideoProfile::operator!=(const MltVideoProfile &other) const {
bool MltVideoProfile::operator!=(const MltVideoProfile &other) const
{
return !(*this == other);
}
CommentedTime::CommentedTime(): t(GenTime(0)), type(0) {}
CommentedTime::CommentedTime(const GenTime &time, const QString &comment, int markerType)
: t(time), c(comment), type(markerType) { }
CommentedTime::CommentedTime(const QString &hash, const GenTime &time)
: t(time), c(hash.section(QLatin1Char(':'), 1)), type(hash.section(QLatin1Char(':'), 0, 0).toInt()) { }
QString CommentedTime::comment() const {
QString CommentedTime::comment() const
{
return (c.isEmpty() ? i18n("Marker") : c);
}
GenTime CommentedTime::time() const {
GenTime CommentedTime::time() const
{
return t;
}
void CommentedTime::setComment(const QString &comm) {
void CommentedTime::setComment(const QString &comm)
{
c = comm;
}
void CommentedTime::setMarkerType(int t) {
void CommentedTime::setMarkerType(int t)
{
type = t;
}
......@@ -195,11 +200,13 @@ QString CommentedTime::hash() const
return QString::number(type) + ":" + (c.isEmpty() ? i18n("Marker") : c);
}
int CommentedTime::markerType() const {
int CommentedTime::markerType() const
{
return type;
}
QColor CommentedTime::markerColor(int type) {
QColor CommentedTime::markerColor(int type)
{
switch (type) {
case 0:
return Qt::red;
......@@ -219,26 +226,32 @@ QColor CommentedTime::markerColor(int type) {
}
}
bool CommentedTime::operator>(const CommentedTime &op) const {
bool CommentedTime::operator>(const CommentedTime &op) const
{
return t > op.time();
}
bool CommentedTime::operator<(const CommentedTime &op) const {
bool CommentedTime::operator<(const CommentedTime &op) const
{
return t < op.time();
}
bool CommentedTime::operator>=(const CommentedTime &op) const {
bool CommentedTime::operator>=(const CommentedTime &op) const
{
return t >= op.time();
}
bool CommentedTime::operator<=(const CommentedTime &op) const {
bool CommentedTime::operator<=(const CommentedTime &op) const
{
return t <= op.time();
}
bool CommentedTime::operator==(const CommentedTime &op) const {
bool CommentedTime::operator==(const CommentedTime &op) const
{
return t == op.time();
}
bool CommentedTime::operator!=(const CommentedTime &op) const {
bool CommentedTime::operator!=(const CommentedTime &op) const
{
return t != op.time();
}
......@@ -17,7 +17,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
......@@ -31,7 +30,8 @@
const int MAXCLIPDURATION = 15000;
namespace Kdenlive {
namespace Kdenlive
{
enum MonitorId {
NoMonitor = 0x01,
......@@ -69,23 +69,25 @@ enum OperationType {
ZoomTimeline
};
namespace PlaylistState {
namespace PlaylistState
{
enum ClipState {
Original = 0,
VideoOnly = 1,
AudioOnly = 2,
Disabled = 3
};
enum ClipState {
Original = 0,
VideoOnly = 1,
AudioOnly = 2,
Disabled = 3
};
};
namespace TimelineMode {
enum EditMode {
NormalEdit = 0,
OverwriteEdit = 1,
InsertEdit = 2
};
namespace TimelineMode
{
enum EditMode {
NormalEdit = 0,
OverwriteEdit = 1,
InsertEdit = 2
};
};
enum ClipType {
......@@ -183,7 +185,8 @@ enum TrimMode {
SlideTrim
};
class TrackInfo {
class TrackInfo
{
public:
TrackType type;
......@@ -202,10 +205,9 @@ public:
effectsList(true) {}
};
struct ProfileInfo {
QSize profileSize;
double profileFps;
QSize profileSize;
double profileFps;
};
struct requestClipInfo {
......@@ -224,7 +226,8 @@ typedef QMap<QString, QString> stringMap;
typedef QMap <int, QMap <int, QByteArray> > audioByteArray;
typedef QVector<qint16> audioShortVector;
class ItemInfo {
class ItemInfo
{
public:
/** startPos is the position where the clip starts on the track */
GenTime startPos;
......@@ -237,12 +240,15 @@ public:
/** Track number */
int track;
ItemInfo() : track(0) {}
bool isValid() const {
bool isValid() const
{
return startPos != endPos;
}
bool contains(GenTime pos) const {
if (startPos == endPos)
bool contains(GenTime pos) const
{
if (startPos == endPos) {
return true;
}
return (pos <= endPos && pos >= startPos);
}
bool operator==(const ItemInfo &a)
......@@ -251,7 +257,8 @@ public:
}
};
class TransitionInfo {
class TransitionInfo
{
public:
/** startPos is the position where the clip starts on the track */
GenTime startPos;
......@@ -269,7 +276,8 @@ public:
forceTrack(0) {}
};
class MltVideoProfile {
class MltVideoProfile
{
public:
QString path;
QString description;
......@@ -287,7 +295,7 @@ public:
void adjustWidth();
MltVideoProfile();
explicit MltVideoProfile(const QVariantList &params);
bool operator==(const MltVideoProfile& point) const;
bool operator==(const MltVideoProfile &point) const;
bool operator!=(const MltVideoProfile &other) const;
/** @brief Returns true if both profiles have same fps, and can be mixed with the xml producer */
bool isCompatible(const MltVideoProfile &point) const;
......@@ -297,14 +305,12 @@ public:
const QString dialogDescriptiveString();
};
class CommentedTime
{
public:
CommentedTime();
CommentedTime(const GenTime &time, const QString& comment, int markerType = 0);
CommentedTime(const QString& hash, const GenTime &time);
CommentedTime(const GenTime &time, const QString &comment, int markerType = 0);
CommentedTime(const QString &hash, const GenTime &time);
QString comment() const;
GenTime time() const;
......
This diff is collapsed.
......@@ -17,19 +17,16 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef DOCUMENTCHECKER_H
#define DOCUMENTCHECKER_H
#include "ui_missingclips_ui.h"
#include "definitions.h"
#include <QDir>
#include <QUrl>
#include <QDomElement>
class DocumentChecker: public QObject
{
Q_OBJECT
......@@ -81,6 +78,5 @@ private:
void fixProxyClip(const QString &id, const QString &oldUrl, const QString &newUrl, const QDomNodeList &producers);
};
#endif
This diff is collapsed.
......@@ -17,7 +17,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef DOCUMENTVALIDATOR_H
#define DOCUMENTVALIDATOR_H
......@@ -51,7 +50,7 @@ private:
/** @brief Make sur we don't have orphaned producers (that are not in Bin). */
void checkOrphanedProducers();
QStringList getInfoFromEffectName(const QString &oldName);
QString colorToString(const QColor& c);
QString colorToString(const QColor &c);
/*
/// @brief Updates effects that were created using a different version of the underlaying filter than the one installed.
void updateEffects();
......
This diff is collapsed.
......@@ -56,13 +56,14 @@ class QUndoGroup;
class QTimer;
class QUndoGroup;
namespace Mlt {
class Profile;
namespace Mlt
{
class Profile;
}
class DocUndoStack: public QUndoStack
{
Q_OBJECT
Q_OBJECT
public:
explicit DocUndoStack(QUndoGroup *parent = Q_NULLPTR);
void push(QUndoCommand *cmd);
......@@ -75,7 +76,7 @@ class KdenliveDoc: public QObject
Q_OBJECT
public:
KdenliveDoc(const QUrl &url, const QString &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QMap<QString, QString>& properties, const QMap<QString, QString>& metadata, const QPoint &tracks, Render *render, NotesPlugin *notes, bool *openBackup, MainWindow *parent = Q_NULLPTR);
KdenliveDoc(const QUrl &url, const QString &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QMap<QString, QString> &properties, const QMap<QString, QString> &metadata, const QPoint &tracks, Render *render, NotesPlugin *notes, bool *openBackup, MainWindow *parent = Q_NULLPTR);
~KdenliveDoc();
QDomNodeList producersList();
double fps() const;
......@@ -139,7 +140,7 @@ public:
/** @brief Returns the document metadata (author, copyright, ...) */
const QMap<QString, QString> metadata() const;
/** @brief Set the document metadata (author, copyright, ...) */
void setMetadata(const QMap<QString, QString>& meta);
void setMetadata(const QMap<QString, QString> &meta);
/** @brief Get frame size of the renderer (profile)*/
const QSize getRenderSize() const;
/** @brief Add url to the file watcher so that we monitor changes */
......@@ -169,13 +170,13 @@ public:
void displayMessage(const QString &text, MessageType type = DefaultMessage, int timeOut = 0);
/** @brief Get a cache directory for this project. */
QDir getCacheDir(CacheType type, bool *ok) const;
/** @brief Create standard cache dirs for the project */
/** @brief Create standard cache dirs for the project */
void initCacheDirs();
/** @brief Get a list of all proxy hash used in this project */
/** @brief Get a list of all proxy hash used in this project */
QStringList getProxyHashList();
/** @brief Returns true if advanced compositing is available */
/** @brief Returns true if advanced compositing is available */
static int compositingMode();
/** @brief Move project data files to new url */
/** @brief Move project data files to new url */
void moveProjectData(const QString &src, const QString &dest);
private:
......
......@@ -7,7 +7,7 @@ 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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
......@@ -30,7 +30,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//static
QPixmap KThumb::getImage(const QUrl &url, int width, int height)
{
if (!url.isValid()) return QPixmap();
if (!url.isValid()) {
return QPixmap();
}
return getImage(url, 0, width, height);
}
......@@ -42,7 +44,9 @@ QPixmap KThumb::getImage(const QUrl &url, int frame, int width, int height)
height = width * profile.height() / profile.width();
}
QPixmap pix(width, height);
if (!url.isValid()) return pix;
if (!url.isValid()) {
return pix;
}
Mlt::Producer *producer = new Mlt::Producer(profile, url.path().toUtf8().constData());
pix = QPixmap::fromImage(getFrame(producer, frame, width, height));
delete producer;
......@@ -70,7 +74,6 @@ QImage KThumb::getFrame(Mlt::Producer *producer, int framepos, int displayWidth,
return p;
}
//static
QImage KThumb::getFrame(Mlt::Frame *frame, int width, int height)
{
......@@ -84,7 +87,7 @@ QImage KThumb::getFrame(Mlt::Frame *frame, int width, int height)
mlt_image_format format = mlt_image_rgb24a;
//frame->set("progressive", "1");
ow += ow % 2;
const uchar* imagedata = frame->get_image(format, ow, oh);
const uchar *imagedata = frame->get_image(format, ow, oh);
if (imagedata) {
QImage image(ow, oh, QImage::Format_RGBA8888);
memcpy(image.bits(), imagedata, ow * oh * 4);
......@@ -106,29 +109,30 @@ QImage KThumb::getFrame(Mlt::Frame *frame, int width, int height)
}
//static
uint KThumb::imageVariance(const QImage &image )
uint KThumb::imageVariance(const QImage &image)
{
uint delta = 0;
uint avg = 0;
uint bytes = image.byteCount();
uint STEPS = bytes/2;
uint STEPS = bytes / 2;
QVarLengthArray<uchar> pivot(STEPS);
const uchar *bits=image.bits();
const uchar *bits = image.bits();
// First pass: get pivots and taking average
for( uint i=0; i<STEPS ; ++i ){
for (uint i = 0; i < STEPS; ++i) {
pivot[i] = bits[2 * i];
avg+=pivot.at(i);
avg += pivot.at(i);
}
if (STEPS) {
avg = avg / STEPS;
}
if (STEPS)
avg=avg/STEPS;
// Second Step: calculate delta (average?)
for (uint i=0; i<STEPS; ++i)
{
int curdelta=abs(int(avg - pivot.at(i)));
delta+=curdelta;
for (uint i = 0; i < STEPS; ++i) {
int curdelta = abs(int(avg - pivot.at(i)));
delta += curdelta;
}
if (STEPS)
return delta/STEPS;
else
if (STEPS) {
return delta / STEPS;
} else {
return 0;
}
}
......@@ -7,7 +7,7 @@ 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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
......@@ -27,7 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <mlt++/Mlt.h>
namespace Mlt
{
class Producer;
......@@ -36,14 +35,14 @@ class Frame;
namespace KThumb
{
QPixmap getImage(const QUrl &url, int width, int height = -1);
QPixmap getImage(const QUrl &url, int frame, int width, int height = -1);
QImage getFrame(Mlt::Producer *producer, int framepos, int displayWidth, int height);
QImage getFrame(Mlt::Frame *frame, int width, int height);
/** @brief Calculates image variance, useful to know if a thumbnail is interesting.
* @return an integer between 0 and 100. 0 means no variance, eg. black image while bigger values mean contrasted image
* */
uint imageVariance(const QImage &image);
QPixmap getImage(const QUrl &url, int width, int height = -1);
QPixmap getImage(const QUrl &url, int frame, int width, int height = -1);
QImage getFrame(Mlt::Producer *producer, int framepos, int displayWidth, int height);
QImage getFrame(Mlt::Frame *frame, int width, int height);
/** @brief Calculates image variance, useful to know if a thumbnail is interesting.
* @return an integer between 0 and 100. 0 means no variance, eg. black image while bigger values mean contrasted image
* */
uint imageVariance(const QImage &image);
};
#endif
......@@ -527,25 +527,25 @@ void GraphicsSceneRectMove::keyPressEvent(QKeyEvent *keyEvent)
}
switch (keyEvent->key()) {
case Qt::Key_Left:
foreach (QGraphicsItem * qgi, selectedItems()) {
foreach (QGraphicsItem *qgi, selectedItems()) {
qgi->moveBy(-diff, 0);
}
emit itemMoved();
break;
case Qt::Key_Right:
foreach (QGraphicsItem * qgi, selectedItems()) {
foreach (QGraphicsItem *qgi, selectedItems()) {
qgi->moveBy(diff, 0);
}
emit itemMoved();
break;
case Qt::Key_Up:
foreach (QGraphicsItem * qgi, selectedItems()) {
foreach (QGraphicsItem *qgi, selectedItems()) {
qgi->moveBy(0, -diff);
}
emit itemMoved();
break;
case Qt::Key_Down:
foreach (QGraphicsItem * qgi, selectedItems()) {
foreach (QGraphicsItem *qgi, selectedItems()) {
qgi->moveBy(0, diff);
}
emit itemMoved();
......
......@@ -51,69 +51,81 @@ public:
QString toString() const;
/*
* Operators.
*/
/// Unary minus
GenTime operator -() {
GenTime operator -()
{
return GenTime(-m_time);
}
/// Addition
GenTime & operator+=(GenTime op) {
GenTime &operator+=(GenTime op)
{
m_time += op.m_time;
return *this;
}