Starting KDE4 porting

svn path=/branches/KDE4/; revision=1777
parents
project(kdenlive)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )
# search packages used by KDE
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include (MacroLibrary)
include(MacroOptionalAddSubdirectory)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories (${QDBUS_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${CMAKE_SOURCE_DIR}/widgets)
FIND_PACKAGE(LIBMLT REQUIRED)
FIND_PACKAGE(LIBMLTPLUS REQUIRED)
FIND_PACKAGE(LIBFFMPEG REQUIRED)
add_subdirectory(src)
\ No newline at end of file
add_subdirectory( widgets )
include_directories(
${CMAKE_SOURCE_DIR}/src/widgets
${LIBMLT_INCLUDE_DIR}
${LIBMLTPLUS_INCLUDE_DIR}
${LIBFFMPEG_INCLUDE_DIR}
)
LINK_DIRECTORIES(
${LIBMLT_LIBRARY}
${LIBMLTPLUS_LIBRARY}
${LIBFFMPEG_LIBRARY}
)
kde4_add_ui_files(kdenlive_UI
widgets/timeline_ui.ui
widgets/projectlist_ui.ui
widgets/monitor_ui.ui
)
set(kdenlive_SRCS
main.cpp
mainwindow.cpp
customruler.cpp
projectlist.cpp
projectitem.cpp
monitor.cpp
gentime.cpp
renderer.cpp
kdenlivedoc.cpp
trackview.cpp
docclipbase.cpp
timecode.cpp
)
kde4_add_executable(kdenlive ${kdenlive_SRCS} ${kdenlive_UI})
target_link_libraries(kdenlive
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
${LIBMLTPLUS_LIBRARY}
${LIBMLT_LIBRARY}
)
install(TARGETS kdenlive DESTINATION ${BIN_INSTALL_DIR})
install( FILES kdenliveui.rc
DESTINATION ${DATA_INSTALL_DIR}/kdenlive )
\ No newline at end of file
#include <QMouseEvent>
#include <QStylePainter>
#include <KDebug>
#include "customruler.h"
#define INIT_VALUE 0
#define INIT_MIN_VALUE 0
#define INIT_MAX_VALUE 100
#define INIT_TINY_MARK_DISTANCE 1
#define INIT_LITTLE_MARK_DISTANCE 5
#define INIT_MIDDLE_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 2)
#define INIT_BIG_MARK_DISTANCE (INIT_LITTLE_MARK_DISTANCE * 10)
#define INIT_SHOW_TINY_MARK false
#define INIT_SHOW_LITTLE_MARK true
#define INIT_SHOW_MEDIUM_MARK true
#define INIT_SHOW_BIG_MARK true
#define INIT_SHOW_END_MARK true
#define INIT_SHOW_POINTER true
#define INIT_SHOW_END_LABEL true
#define INIT_PIXEL_PER_MARK (double)10.0 /* distance between 2 base marks in pixel */
#define INIT_OFFSET (-20)
#define INIT_LENGTH_FIX true
#define INIT_END_OFFSET 0
#define FIX_WIDTH 20 /* widget width in pixel */
#define LINE_END (FIX_WIDTH - 3)
#define END_MARK_LENGTH (FIX_WIDTH - 6)
#define END_MARK_X2 LINE_END
#define END_MARK_X1 (END_MARK_X2 - END_MARK_LENGTH)
#define BIG_MARK_LENGTH (END_MARK_LENGTH*3/4)
#define BIG_MARK_X2 LINE_END
#define BIG_MARK_X1 (BIG_MARK_X2 - BIG_MARK_LENGTH)
#define MIDDLE_MARK_LENGTH (END_MARK_LENGTH/2)
#define MIDDLE_MARK_X2 LINE_END
#define MIDDLE_MARK_X1 (MIDDLE_MARK_X2 - MIDDLE_MARK_LENGTH)
#define LITTLE_MARK_LENGTH (MIDDLE_MARK_LENGTH/2)
#define LITTLE_MARK_X2 LINE_END
#define LITTLE_MARK_X1 (LITTLE_MARK_X2 - LITTLE_MARK_LENGTH)
#define BASE_MARK_LENGTH (LITTLE_MARK_LENGTH/2)
#define BASE_MARK_X2 LINE_END
#define BASE_MARK_X1 (BASE_MARK_X2 - 3) //BASE_MARK_LENGTH
#define LABEL_SIZE 8
#define END_LABEL_X 4
#define END_LABEL_Y (END_LABEL_X + LABEL_SIZE - 2)
#define FRAME_SIZE 90
const int CustomRuler::comboScale[] =
{ 1, 2, 5, 10, 25, 50, 125, 250, 500, 725, 1500, 3000, 6000,
12000 };
CustomRuler::CustomRuler(QWidget *parent)
: KRuler(parent)
{
slotNewOffset(0);
setRulerMetricStyle(KRuler::Pixel);
setLength(1024);
setMaximum(1024);
setPixelPerMark(3);
setLittleMarkDistance (FRAME_SIZE);
setMediumMarkDistance (FRAME_SIZE * 25);
setBigMarkDistance (FRAME_SIZE * 25 * 60);
}
// virtual
void CustomRuler::mousePressEvent ( QMouseEvent * event )
{
int pos = event->x();
slotNewValue( pos );
kDebug()<<pos;
}
void CustomRuler::slotNewValue ( int _value )
{
m_cursorPosition = _value / pixelPerMark();
KRuler::slotNewValue(_value);
}
void CustomRuler::setPixelPerMark (double rate)
{
int scale = comboScale[(int) rate];
int newPos = m_cursorPosition * (1.0 / scale);
KRuler::setPixelPerMark(1.0 / scale);
KRuler::slotNewValue( newPos );
}
// virtual
void CustomRuler::paintEvent(QPaintEvent * /*e*/)
{
// debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");
QStylePainter p(this);
int value = this->value(),
minval = minimum(),
maxval;
maxval = maximum()
+ offset() - endOffset();
//ioffsetval = value-offset;
// pixelpm = (int)ppm;
// left = clip.left(),
// right = clip.right();
double f, fend,
offsetmin=(double)(minval-offset()),
offsetmax=(double)(maxval-offset()),
fontOffset = (((double)minval)>offsetmin)?(double)minval:offsetmin;
// draw labels
QFont font = p.font();
font.setPointSize(LABEL_SIZE);
p.setFont( font );
// draw littlemarklabel
// draw mediummarklabel
// draw bigmarklabel
// draw endlabel
/*if (d->showEndL) {
if (d->dir == Qt::Horizontal) {
p.translate( fontOffset, 0 );
p.drawText( END_LABEL_X, END_LABEL_Y, d->endlabel );
}*/
// draw the tiny marks
//if (showTinyMarks())
/*{
fend = pixelPerMark()*tinyMarkDistance();
if (fend > 5) for ( f=offsetmin; f<offsetmax; f+=fend ) {
p.drawLine((int)f, BASE_MARK_X1, (int)f, BASE_MARK_X2);
}
}*/
if (showLittleMarks()) {
// draw the little marks
fend = pixelPerMark()*littleMarkDistance();
if (fend > 5) for ( f=offsetmin; f<offsetmax; f+=fend ) {
p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
if (fend > 30) p.drawText( (int)f + 2, LABEL_SIZE, QString::number((f - offsetmin) / pixelPerMark() / FRAME_SIZE) );
}
}
if (showMediumMarks()) {
// draw medium marks
fend = pixelPerMark()*mediumMarkDistance();
if (fend > 5) for ( f=offsetmin; f<offsetmax; f+=fend ) {
p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
if (fend > 30) p.drawText( (int)f + 2, LABEL_SIZE, QString::number((f - offsetmin) / pixelPerMark() / FRAME_SIZE) );
}
}
if (showBigMarks()) {
// draw big marks
fend = pixelPerMark()*bigMarkDistance();
if (fend > 5) for ( f=offsetmin; f<offsetmax; f+=fend ) {
p.drawLine((int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2);
if (fend > 30) p.drawText( (int)f + 2, LABEL_SIZE, QString::number((f - offsetmin) / pixelPerMark() / FRAME_SIZE) );
}
}
/* if (d->showem) {
// draw end marks
if (d->dir == Qt::Horizontal) {
p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2);
p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2);
}
else {
p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset);
p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset);
}
}*/
// draw pointer
if (showPointer()) {
QPolygon pa(4);
pa.setPoints(3, value-6, 9, value+6, 9, value/*+0*/, 16);
p.setBrush( QBrush(Qt::yellow) );
p.drawPolygon( pa );
}
}
#include "customruler.moc"
#ifndef CUSTOMRULER_H
#define CUSTOMRULER_H
#include <KRuler>
class CustomRuler : public KRuler
{
Q_OBJECT
public:
CustomRuler(QWidget *parent=0);
virtual void mousePressEvent ( QMouseEvent * event );
void setPixelPerMark (double rate);
static const int comboScale[];
protected:
virtual void paintEvent(QPaintEvent * /*e*/);
private:
int m_cursorPosition;
public slots:
void slotNewValue ( int _value );
};
#endif
/**************************1*************************************************
DocClipBase.cpp - description
-------------------
begin : Fri Apr 12 2002
copyright : (C) 2002 by Jason Wood
email : jasonwood@blueyonder.co.uk
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <KDebug>
#include "docclipbase.h"
/*#include "docclipavfile.h"
#include "doccliptextfile.h"
#include "docclipproject.h"
#include "doctrackbase.h"*/
DocClipBase::DocClipBase():
m_description(""), m_refcount(0), m_projectThumbFrame(0), audioThumbCreated(false)
{
//thumbCreator = 0;
}
DocClipBase::~DocClipBase()
{
//delete thumbCreator;
}
void DocClipBase::setName(const QString name)
{
m_name = name;
}
const QString & DocClipBase::name() const
{
return m_name;
}
uint DocClipBase::getId() const
{
return m_id;
}
void DocClipBase::setId( const uint &newId)
{
m_id = newId;
}
void DocClipBase::setProjectThumbFrame( const uint &ix)
{
m_projectThumbFrame = ix;
}
uint DocClipBase::getProjectThumbFrame() const
{
return m_projectThumbFrame;
}
void DocClipBase::setDescription(const QString & description)
{
m_description = description;
}
const QString & DocClipBase::description() const
{
return m_description;
}
// virtual
QDomDocument DocClipBase::toXML() const
{
QDomDocument doc;
QDomElement clip = doc.createElement("kdenliveclip");
QDomText text = doc.createTextNode(description());
clip.appendChild(text);
doc.appendChild(clip);
return doc;
}
DocClipBase *DocClipBase::
createClip(KdenliveDoc *doc, const QDomElement & element)
{
DocClipBase *clip = 0;
QString description;
QDomNode node = element;
node.normalize();
if (element.tagName() != "kdenliveclip") {
kWarning() <<
"DocClipBase::createClip() element has unknown tagName : " <<
element.tagName() << endl;
return 0;
}
QDomNode n = element.firstChild();
while (!n.isNull()) {
QDomElement e = n.toElement();
if (!e.isNull()) {
QString tagName = e.tagName();
if (e.tagName() == "avfile") {
// clip = DocClipAVFile::createClip(e);
} else if (e.tagName() == "DocTrackBaseList") {
// clip = DocClipProject::createClip(doc, e);
}
} else {
QDomText text = n.toText();
if (!text.isNull()) {
description = text.nodeValue();
}
}
n = n.nextSibling();
}
if (clip == 0) {
kWarning() << "DocClipBase::createClip() unable to create clip" <<
endl;
} else {
// setup DocClipBase specifics of the clip.
clip->setDescription(description);
clip->setAudioThumbCreated(false);
}
return clip;
}
void DocClipBase::setAudioThumbCreated(bool isDone)
{
audioThumbCreated = isDone;
}
QDomDocument DocClipBase::generateSceneList(bool, bool) const
{
}
void DocClipBase::setThumbnail(const QPixmap & pixmap)
{
m_thumbnail = pixmap;
}
const QPixmap & DocClipBase::thumbnail() const
{
return m_thumbnail;
}
void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
{
audioFrameChache = data;
audioThumbCreated = true;
}
QList < GenTime > DocClipBase::snapMarkers() const
{
QList < GenTime > markers;
for (uint count = 0; count < m_snapMarkers.count(); ++count) {
markers.append(m_snapMarkers[count].time());
}
return markers;
}
QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
{
return m_snapMarkers;
}
void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
{
m_snapMarkers = markers;
}
void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
{
QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
if ((*it).time() >= time)
break;
}
if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
kError() <<
"trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
<< endl;
} else {
CommentedTime t(time, comment);
m_snapMarkers.insert(it, t);
}
}
void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
{
QList < CommentedTime >::Iterator it;
for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
if ((*it).time() == time)
break;
}
if (it != m_snapMarkers.end()) {
(*it).setComment(comment);
} else {
kError() <<
"trying to edit Snap Marker that does not already exists" << endl;
}
}
QString DocClipBase::deleteSnapMarker(const GenTime & time)
{
QString result = i18n("Marker");
QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
while (itt != m_snapMarkers.end()) {
if ((*itt).time() == time)
break;
++itt;
}
if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
result = (*itt).comment();
m_snapMarkers.erase(itt);
}
return result;
}
GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
{
QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
while (itt != m_snapMarkers.end()) {
if ((*itt).time() == time)
return time;
++itt;
}
return GenTime(0.0);
}
GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
{
int it;
for ( it = 0; it < m_snapMarkers.count(); it++ ) {
if (m_snapMarkers[it].time() >= currTime)
break;
}
if (it == 0) return GenTime();
else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
return m_snapMarkers[it].time();
else return m_snapMarkers[it-1].time();
}
GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
{
int it;
for ( it = 0; it < m_snapMarkers.count(); it++ ) {
if (m_snapMarkers[it].time() > currTime)
break;
}
if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
return duration();
}
QString DocClipBase::markerComment(GenTime t)
{
QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
while (itt != m_snapMarkers.end()) {
if ((*itt).time() == t)
return (*itt).comment();
++itt;
}
return QString::null;
}
//static
QString DocClipBase::getTypeName(CLIPTYPE type)
{
QString result;
switch (type) {
case AV:
result = i18n("Video Clip");
break;
case COLOR:
result = i18n("Color Clip");
break;
case PLAYLIST:
result = i18n("Playlist Clip");
break;
case IMAGE:
result = i18n("Image Clip");
break;
case SLIDESHOW:
result = i18n("Slideshow Clip");
break;
case VIRTUAL:
result = i18n("Virtual Clip");
break;
case AUDIO:
result = i18n("Audio Clip");
break;
case VIDEO:
result = i18n("Mute Video Clip");
break;
case TEXT:
result = i18n("Text Clip");
break;
default:
result = i18n("None");
break;
}
return result;
}
/***************************************************************************
docclipbase.h - description
-------------------
begin : Fri Apr 12 2002
copyright : (C) 2002 by Jason Wood
email : jasonwood@blueyonder.co.uk
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef DOCCLIPBASE_H
#define DOCCLIPBASE_H
/**DocClip is a class for the various types of clip
*@author Jason Wood
*/
#include <qdom.h>
#include <qobject.h>
#include <qpixmap.h>
#include <kurl.h>
#include <klocale.h>
#include "gentime.h"
// #include "kthumb.h"
/*