From: Till T. <ro...@tt...> - 2012-06-08 07:19:48
|
Git commit 6ac3368bef2326636e64068045c5454af7333877 by Till Theato. Committed on 07/06/2012 at 16:34. Pushed by theato into branch 'refactoring'. Add timeline position bar/ruler. M +4 -3 src/core/bin/bin.cpp M +1 -1 src/core/bin/bin.h M +4 -4 src/core/core.cpp M +2 -2 src/core/core.h M +1 -1 src/core/fraction.h M +7 -2 src/core/mainwindow.cpp M +6 -3 src/core/monitor/monitormodel.cpp M +4 -7 src/core/project/projectmanager.cpp M +4 -1 src/core/project/projectmanager.h M +5 -0 src/core/project/timeline.cpp M +1 -0 src/core/project/timeline.h M +5 -5 src/core/timecode.cpp M +6 -6 src/core/timecode.h M +4 -0 src/core/timecodeformatter.cpp M +8 -2 src/core/timecodeformatter.h M +1 -0 src/core/timelineview/CMakeLists.txt A +271 -0 src/core/timelineview/timelinepositionbar.cpp [License: GPL (v2+)] A +76 -0 src/core/timelineview/timelinepositionbar.h [License: GPL (v2+)] M +10 -2 src/core/timelineview/timelinewidget.cpp M +3 -0 src/core/timelineview/timelinewidget.h http://commits.kde.org/kdenlive/6ac3368bef2326636e64068045c5454af7333877 diff --git a/src/core/bin/bin.cpp b/src/core/bin/bin.cpp index 88ef052..08893e7 100644 --- a/src/core/bin/bin.cpp +++ b/src/core/bin/bin.cpp @@ -11,19 +11,22 @@ the Free Software Foundation, either version 3 of the License, or #include "bin.h" #include "projectitemmodel.h" #include "project/project.h" +#include "project/projectmanager.h" +#include "core.h" #include <QVBoxLayout> #include <QTreeView> Bin::Bin(QWidget* parent) : QWidget(parent), - m_project(NULL), m_itemModel(NULL), m_itemView(NULL) { // TODO: proper ui, search line, add menu, ... QVBoxLayout *layout = new QVBoxLayout(this); + connect(pCore->projectManager(), SIGNAL(projectOpened(Project*)), this, SLOT(setProject(Project*))); + } Bin::~Bin() @@ -45,8 +48,6 @@ void Bin::setProject(Project* project) delete m_itemModel; } - m_project = project; - m_itemModel = new ProjectItemModel(project, this); m_itemView = new QTreeView(); diff --git a/src/core/bin/bin.h b/src/core/bin/bin.h index f6f909a..b33a143 100644 --- a/src/core/bin/bin.h +++ b/src/core/bin/bin.h @@ -27,11 +27,11 @@ public: Bin(QWidget* parent = 0); ~Bin(); +public slots: void setProject(Project *project); private: - Project *m_project; ProjectItemModel *m_itemModel; QAbstractItemView *m_itemView; }; diff --git a/src/core/core.cpp b/src/core/core.cpp index ce58c88..106f906 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -38,17 +38,17 @@ Core::~Core() m_self = 0; } -void Core::initialize(MainWindow* mainWindow, const KUrl &projectUrl, const QString &clipsToLoad) +void Core::initialize(MainWindow* mainWindow) { m_self = new Core(mainWindow); - m_self->init(projectUrl, clipsToLoad); + m_self->init(); } -void Core::init(const KUrl &projectUrl, const QString &clipsToLoad) +void Core::init() { m_effectRepository = new EffectRepository(); m_clipPluginManager = new ClipPluginManager(); - m_projectManager = new ProjectManager(projectUrl, clipsToLoad); + m_projectManager = new ProjectManager(); } Core* Core::self() diff --git a/src/core/core.h b/src/core/core.h index 5bff5c3..0155260 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -32,7 +32,7 @@ class Core : public QObject public: virtual ~Core(); - static void initialize(MainWindow *mainWindow, const KUrl &projectUrl, const QString &clipsToLoad); + static void initialize(MainWindow *mainWindow); static Core *self(); @@ -45,7 +45,7 @@ public: private: Core(MainWindow *mainWindow); static Core *m_self; - void init(const KUrl &projectUrl, const QString &clipsToLoad); + void init(); MainWindow *m_mainWindow; Project *m_currentProject; diff --git a/src/core/fraction.h b/src/core/fraction.h index e1dbf00..f5d93f7 100644 --- a/src/core/fraction.h +++ b/src/core/fraction.h @@ -18,7 +18,7 @@ public: Fraction(int num, int den); Fraction(); - inline double value() const; + double value() const; int numerator; int denominator; diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 367f29d..60f7efc 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -12,6 +12,7 @@ the Free Software Foundation, either version 3 of the License, or #include "core.h" #include "kdenlivesettings.h" #include "project/project.h" +#include "project/projectmanager.h" #include "bin/bin.h" #include "monitor/monitorview.h" #include "timelineview/timelinewidget.h" @@ -30,6 +31,8 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl &url, const QString & { initLocale(); + Core::initialize(this); + QDockWidget *binDock = new QDockWidget(i18n("Bin"), this); binDock->setObjectName("bin"); m_bin = new Bin(); @@ -45,11 +48,13 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl &url, const QString & m_timeline = new TimelineWidget(this); setCentralWidget(m_timeline); - Core::initialize(this, url, clipsToLoad); - KStandardAction::quit(this, SLOT(close()), actionCollection()); setupGUI(); + + if (!url.isEmpty() && url.isValid()) { + pCore->projectManager()->openProject(url); + } } MainWindow::~MainWindow() diff --git a/src/core/monitor/monitormodel.cpp b/src/core/monitor/monitormodel.cpp index 5c1f85a..96db43a 100644 --- a/src/core/monitor/monitormodel.cpp +++ b/src/core/monitor/monitormodel.cpp @@ -19,7 +19,8 @@ MonitorModel::MonitorModel(Project* project) : QObject(project), m_project(project), m_producer(NULL), - m_frame(NULL) + m_frame(NULL), + m_position(-1) { // do this in Project // setenv("MLT_PROFILE", KdenliveSettings::current_profile().toUtf8().constData(), 1); @@ -60,6 +61,7 @@ void MonitorModel::setProducer(ProducerWrapper* producer) m_producer = producer; m_producer->set_speed(0.); + m_position = -1; // should we mlt_service_disconnect ? m_consumer->connect(*static_cast<Mlt::Service *>(producer)); @@ -107,7 +109,8 @@ void MonitorModel::togglePlaybackState() void MonitorModel::setPosition(int position) { - if (m_producer) { + if (m_producer && position != m_position) { + m_position = position; m_producer->seek(position); if (speed() == 0) { refreshConsumer(); @@ -118,7 +121,7 @@ void MonitorModel::setPosition(int position) int MonitorModel::position() const { - return m_consumer->position(); + return m_position; } void MonitorModel::setSpeed(double speed) diff --git a/src/core/project/projectmanager.cpp b/src/core/project/projectmanager.cpp index a74b4ec..6f2cc5c 100644 --- a/src/core/project/projectmanager.cpp +++ b/src/core/project/projectmanager.cpp @@ -19,15 +19,11 @@ the Free Software Foundation, either version 3 of the License, or #include <KActionCollection> -ProjectManager::ProjectManager(const KUrl& projectUrl, const QString& clipsToLoad, QObject* parent) : +ProjectManager::ProjectManager(QObject* parent) : QObject(parent), m_project(NULL) { KStandardAction::open(this, SLOT(execOpenFileDialog()), pCore->window()->actionCollection()); - - if (!projectUrl.isEmpty()) { - openProject(projectUrl); - } } ProjectManager::~ProjectManager() @@ -56,8 +52,9 @@ void ProjectManager::openProject(const KUrl& url) delete m_project; } m_project = new Project(url, this); - pCore->window()->bin()->setProject(m_project); - pCore->window()->timelineWidget()->setProject(m_project); + emit projectOpened(m_project); + + // remove line when monitormanager is introduced pCore->window()->monitorWidget()->setModel(m_project->monitor()); } diff --git a/src/core/project/projectmanager.h b/src/core/project/projectmanager.h index 1d2efe5..7f460c3 100644 --- a/src/core/project/projectmanager.h +++ b/src/core/project/projectmanager.h @@ -22,7 +22,7 @@ class ProjectManager : public QObject Q_OBJECT public: - explicit ProjectManager(const KUrl &projectUrl, const QString &clipsToLoad, QObject* parent = 0); + explicit ProjectManager(QObject* parent = 0); virtual ~ProjectManager(); Project *current(); @@ -32,6 +32,9 @@ public: public slots: void execOpenFileDialog(); +signals: + void projectOpened(Project *project); + private: Project *m_project; }; diff --git a/src/core/project/timeline.cpp b/src/core/project/timeline.cpp index 46f98fc..e0f9972 100644 --- a/src/core/project/timeline.cpp +++ b/src/core/project/timeline.cpp @@ -59,6 +59,11 @@ Mlt::Profile* Timeline::profile() return m_profile; } +ProducerWrapper* Timeline::producer() +{ + return m_producer; +} + void Timeline::loadTracks() { Q_ASSERT(m_tracks.count() == 0); diff --git a/src/core/project/timeline.h b/src/core/project/timeline.h index 030ee74..32f0bb6 100644 --- a/src/core/project/timeline.h +++ b/src/core/project/timeline.h @@ -35,6 +35,7 @@ public: Project *project(); QList<TimelineTrack *> tracks(); Mlt::Profile *profile(); + ProducerWrapper *producer(); void loadTracks(); diff --git a/src/core/timecode.cpp b/src/core/timecode.cpp index 3500125..99cb6fe 100644 --- a/src/core/timecode.cpp +++ b/src/core/timecode.cpp @@ -15,25 +15,25 @@ the Free Software Foundation, either version 3 of the License, or #include "project/project.h" -Timecode::Timecode(TimecodeFormatter* formatter) : +Timecode::Timecode(TimecodeFormatter const* formatter) : m_frames(0) { setFormatter(formatter); } -Timecode::Timecode(double seconds, TimecodeFormatter* formatter) +Timecode::Timecode(double seconds, TimecodeFormatter const* formatter) { setFormatter(formatter); m_frames = qRound(m_formatter->framerate() * seconds); } -Timecode::Timecode(int frames, TimecodeFormatter* formatter) : +Timecode::Timecode(int frames, TimecodeFormatter const* formatter) : m_frames(frames) { setFormatter(formatter); } -void Timecode::setFormatter(TimecodeFormatter* formatter) +void Timecode::setFormatter(TimecodeFormatter const* formatter) { if (formatter) { m_formatter = formatter; @@ -42,7 +42,7 @@ void Timecode::setFormatter(TimecodeFormatter* formatter) } } -TimecodeFormatter* Timecode::formatter() +TimecodeFormatter const *Timecode::formatter() { return m_formatter; } diff --git a/src/core/timecode.h b/src/core/timecode.h index 15ea19d..3b39654 100644 --- a/src/core/timecode.h +++ b/src/core/timecode.h @@ -18,12 +18,12 @@ the Free Software Foundation, either version 3 of the License, or class Timecode { public: - Timecode(TimecodeFormatter *formatter = 0); - Timecode(double seconds, TimecodeFormatter *formatter = 0); - Timecode(int frames, TimecodeFormatter *formatter = 0); + Timecode(TimecodeFormatter const *formatter = 0); + Timecode(double seconds, TimecodeFormatter const *formatter = 0); + Timecode(int frames, TimecodeFormatter const *formatter = 0); - void setFormatter(TimecodeFormatter *formatter); - TimecodeFormatter *formatter(); + void setFormatter(TimecodeFormatter const *formatter); + TimecodeFormatter const *formatter(); double seconds() const; double milliseconds() const; @@ -50,7 +50,7 @@ public: private: int m_frames; - TimecodeFormatter *m_formatter; + TimecodeFormatter const *m_formatter; }; #endif diff --git a/src/core/timecodeformatter.cpp b/src/core/timecodeformatter.cpp index e2350d5..d287b5a 100644 --- a/src/core/timecodeformatter.cpp +++ b/src/core/timecodeformatter.cpp @@ -37,6 +37,8 @@ void TimecodeFormatter::setFramerate(const Fraction& framerate) m_dropFrames = qRound(m_framerate * .066666); m_framesPer10Minutes = qRound(m_framerate * 600); } + + emit framerateChanged(); } Fraction TimecodeFormatter::framerate() const @@ -51,6 +53,8 @@ void TimecodeFormatter::setDefaultFormat(TimecodeFormatter::Formats format) } else { m_defaultFormat = format; } + + emit defaultFormatChanged(); } TimecodeFormatter::Formats TimecodeFormatter::defaultFormat() const diff --git a/src/core/timecodeformatter.h b/src/core/timecodeformatter.h index b9c07d9..bf5ffdd 100644 --- a/src/core/timecodeformatter.h +++ b/src/core/timecodeformatter.h @@ -12,13 +12,15 @@ the Free Software Foundation, either version 3 of the License, or #define TIMECODEFORMATTER_H #include "fraction.h" -#include <QString> +#include <QObject> class Timecode; -class TimecodeFormatter +class TimecodeFormatter : public QObject { + Q_OBJECT + public: enum Formats { HH_MM_SS_FF, HH_MM_SS_HH, Frames, Seconds, Milliseconds, Time, DefaultFormat }; @@ -33,6 +35,10 @@ public: QString format(const Timecode &timecode, Formats format = DefaultFormat) const; QString mask(const Timecode &timecode) const; +signals: + void framerateChanged(); + void defaultFormatChanged(); + private: QString formatHH_MM_SS_FF(const Timecode &timecode) const; QString formatHH_MM_SS_HH(const Timecode &timecode) const; diff --git a/src/core/timelineview/CMakeLists.txt b/src/core/timelineview/CMakeLists.txt index f63f747..904bde3 100644 --- a/src/core/timelineview/CMakeLists.txt +++ b/src/core/timelineview/CMakeLists.txt @@ -1,6 +1,7 @@ set(timelineview_SRCS timelineview/timelineclipitem.cpp + timelineview/timelinepositionbar.cpp timelineview/timelinescene.cpp timelineview/timelinetrackitem.cpp timelineview/timelinewidget.cpp diff --git a/src/core/timelineview/timelinepositionbar.cpp b/src/core/timelineview/timelinepositionbar.cpp new file mode 100644 index 0000000..f2592d2 --- /dev/null +++ b/src/core/timelineview/timelinepositionbar.cpp @@ -0,0 +1,271 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb...@kd...) * + * * + * 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 "timelinepositionbar.h" +#include "core.h" +#include "project/projectmanager.h" +#include "project/project.h" +#include "timecodeformatter.h" +#include "timecode.h" +#include "project/timeline.h" +#include "project/producerwrapper.h" +#include "monitor/monitormodel.h" +#include <KGlobalSettings> +#include <KLocale> +#include <QMouseEvent> +#include <QPainter> + + +const int TimelinePositionBar::m_comboScale[] = { 1, 2, 5, 10, 25, 50, 125, 250, 500, 750, 1500, 3000, 6000, 12000 }; + + +TimelinePositionBar::TimelinePositionBar(QWidget *parent) : + QWidget(parent), + m_timecodeFormatter(NULL), + m_duration(0), + m_offset(0), + m_playbackPosition(0), + m_zoomLevel(7) +{ + setFont(KGlobalSettings::toolBarFont()); + QFontMetricsF fontMetrics(font()); + m_labelSize = fontMetrics.ascent(); + + setMinimumHeight(m_labelSize * 2); + setMaximumHeight(m_labelSize * 2); + + m_bigMarkX = m_labelSize + 1; + int mark_length = height() - m_bigMarkX; + m_middleMarkX = m_bigMarkX + mark_length / 2; + m_smallMarkX = m_bigMarkX + mark_length / 3; + + setMouseTracking(true); + + connect(pCore->projectManager(), SIGNAL(projectOpened(Project*)), this, SLOT(setProject(Project*))); +} + +void TimelinePositionBar::setDuration(int duration) +{ + int oldduration = m_duration; + m_duration = duration; + update(qMin(oldduration, m_duration) * m_factor - 1 - m_offset, 0, qAbs(oldduration - m_duration) * m_factor + 2, height()); +} + +int TimelinePositionBar::offset() const +{ + return m_offset; +} + +void TimelinePositionBar::setProject(Project* project) +{ + if (m_timecodeFormatter) { + m_timecodeFormatter->disconnect(this); + } + + m_timecodeFormatter = project->timecodeFormatter(); + connect(m_timecodeFormatter, SIGNAL(framerateChanged()), this, SLOT(onFramerateChange())); + connect(m_timecodeFormatter, SIGNAL(defaultFormatChanged()), this, SLOT(update())); + + m_playbackPosition = project->monitor()->position(); + connect(project->monitor(), SIGNAL(positionChanged(int)), this, SLOT(setCursorPosition(int))); + + setDuration(project->timeline()->producer()->get_playtime()); + + updateFrameSize(); +} + +void TimelinePositionBar::setOffset(int offset) +{ + m_offset = offset; + update(); +} + +void TimelinePositionBar::setCursorPosition(int position) +{ + m_playbackPosition = position; + update(); +// if (qAbs(oldpos - newpos) * m_factor > m_textSpacing) { +// update(oldpos * m_factor - offset() - 6, m_bigMarkX, 14, MAX_HEIGHT - m_bigMarkX); +// update(newpos * m_factor - offset() - 6, m_bigMarkX, 14, MAX_HEIGHT - m_bigMarkX); +// } else update(qMin(oldpos, newpos) * m_factor - offset() - 6, m_bigMarkX, qAbs(oldpos - newpos) * m_factor + 14, MAX_HEIGHT - m_bigMarkX); +} + +void TimelinePositionBar::setZoomLevel(int level) +{ + m_zoomLevel = level; + + m_scale = 1 / (double) m_comboScale[level]; + m_factor = m_scale * m_smallMarkDistance; + + m_middleMarkDistance = m_timecodeFormatter->framerate() * m_smallMarkDistance; + if (level > 8) { + m_middleMarkDistance *= 60; + m_bigMarkDistance = m_middleMarkDistance * 5; + } else if (level > 6) { + m_middleMarkDistance *= 10; + m_bigMarkDistance = m_middleMarkDistance * 3; + } else if (level > 3) { + m_bigMarkDistance = m_middleMarkDistance * 5; + } else { + m_bigMarkDistance = m_middleMarkDistance * 60; + } + + switch (level) { + case 0: + m_textSpacing = m_factor; + break; + case 1: + m_textSpacing = m_factor * 5; + break; + case 2: + case 3: + case 4: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor; + break; + case 5: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor * 5; + break; + case 6: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor * 10; + break; + case 7: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor * 30; + break; + case 8: + case 9: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor * 40; + break; + case 10: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor * 80; + break; + case 11: + case 12: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor * 400; + break; + case 13: + m_textSpacing = m_timecodeFormatter->framerate() * m_factor * 800; + break; + } + update(); +} + +void TimelinePositionBar::onFramerateChange() +{ + m_middleMarkDistance = m_timecodeFormatter->framerate() * m_smallMarkDistance; + m_bigMarkDistance = m_middleMarkDistance * 60; + update(); +} + +void TimelinePositionBar::updateFrameSize() +{ + m_smallMarkDistance = 90; // m_view->getFrameWidth(); + onFramerateChange(); + setZoomLevel(m_zoomLevel); +} + +void TimelinePositionBar::mousePressEvent(QMouseEvent* event) +{ + int framePosition = qRound((event->x() + m_offset) / m_factor); + + setFocus(Qt::MouseFocusReason); +// m_view->activateMonitor(); + + emit positionChanged(framePosition); + + // update ? +} + +void TimelinePositionBar::mouseMoveEvent(QMouseEvent* event) +{ + int framePosition = qRound((event->x() + m_offset) / m_factor); + + if (event->buttons() & Qt::LeftButton) { + emit positionChanged(framePosition); + } else { + if (m_timecodeFormatter) { + setToolTip(i18n("Position: %1", Timecode(framePosition, m_timecodeFormatter).formatted())); + } + } +} + +void TimelinePositionBar::paintEvent(QPaintEvent* event) +{ + if (!m_timecodeFormatter) { + return; + } + + QPainter painter(this); + painter.setClipRect(event->rect()); + + const int maxval = (event->rect().right() + m_offset) / m_smallMarkDistance + 1; + + double f, fend; + const int offsetmax = maxval * m_smallMarkDistance; + int offsetmin; + + painter.setPen(palette().text().color()); + + // draw time labels + if (event->rect().y() < m_labelSize) { + offsetmin = (event->rect().left() + m_offset) / m_textSpacing; + offsetmin *= m_textSpacing; + for (f = offsetmin; f < offsetmax; f += m_textSpacing) { + painter.drawText(f - m_offset + 2, m_labelSize, Timecode(static_cast<int>(f / m_factor + 0.5), m_timecodeFormatter).formatted()); + } + } + + // draw the little marks + fend = m_scale * m_smallMarkDistance; + if (fend > 5) { + offsetmin = (event->rect().left() + m_offset) / m_smallMarkDistance; + offsetmin *= m_smallMarkDistance; + for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend) + painter.drawLine(f, m_smallMarkX, f, height()); + } + + // draw medium marks + fend = m_scale * m_middleMarkDistance; + if (fend > 5) { + offsetmin = (event->rect().left() + m_offset) / m_middleMarkDistance; + offsetmin *= m_middleMarkDistance; + for (f = offsetmin - m_offset - fend; f < offsetmax - m_offset + fend; f += fend) + painter.drawLine((int)f, m_middleMarkX, (int)f, height()); + } + + // draw big marks + fend = m_scale * m_bigMarkDistance; + if (fend > 5) { + offsetmin = (event->rect().left() + m_offset) / m_bigMarkDistance; + offsetmin *= m_bigMarkDistance; + for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend) + painter.drawLine((int)f, m_bigMarkX, (int)f, height()); + } + + // draw pointer + painter.setRenderHint(QPainter::Antialiasing); + int position = m_playbackPosition * m_factor - m_offset; + QPolygon pointer(3); + pointer.setPoints(3, position - 6, m_bigMarkX, + position + 6, m_bigMarkX, + position, height() - 1); + painter.setBrush(palette().highlight()); + painter.drawPolygon(pointer); +} + +#include "timelinepositionbar.moc" diff --git a/src/core/timelineview/timelinepositionbar.h b/src/core/timelineview/timelinepositionbar.h new file mode 100644 index 0000000..fbb1431 --- /dev/null +++ b/src/core/timelineview/timelinepositionbar.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb...@kd...) * + * * + * 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 TIMELINEPOSITIONBAR_H +#define TIMELINEPOSITIONBAR_H + +#include <QWidget> + +class Project; +class TimecodeFormatter; + + +class TimelinePositionBar : public QWidget +{ + Q_OBJECT + +public: + TimelinePositionBar(QWidget *parent = 0); + + int offset() const; + +public slots: + void setProject(Project *project); + void setCursorPosition(int position); + void setOffset(int offset); + void setDuration(int duration); + void setZoomLevel(int level); + void onFramerateChange(); + +signals: + void positionChanged(int position); + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event); + +private: + void updateFrameSize(); + + TimecodeFormatter *m_timecodeFormatter; + static const int m_comboScale[]; + int m_duration; + int m_offset; + int m_playbackPosition; + double m_textSpacing; + double m_factor; + double m_scale; + int m_zoomLevel; + + int m_labelSize; + int m_bigMarkX; + int m_middleMarkX; + int m_smallMarkX; + int m_bigMarkDistance; + int m_middleMarkDistance; + int m_smallMarkDistance; +}; + +#endif diff --git a/src/core/timelineview/timelinewidget.cpp b/src/core/timelineview/timelinewidget.cpp index 4c68c86..2ac09c4 100644 --- a/src/core/timelineview/timelinewidget.cpp +++ b/src/core/timelineview/timelinewidget.cpp @@ -10,7 +10,10 @@ the Free Software Foundation, either version 3 of the License, or #include "timelinewidget.h" #include "timelinescene.h" +#include "timelinepositionbar.h" #include "project/project.h" +#include "project/projectmanager.h" +#include "core.h" #include <QGraphicsView> #include <QGridLayout> @@ -21,15 +24,20 @@ TimelineWidget::TimelineWidget(QWidget* parent) : { QGridLayout *layout = new QGridLayout(this); + m_positionBar = new TimelinePositionBar(this); + layout->addWidget(m_positionBar, 0, 0); + m_view = new QGraphicsView(this); m_view->setFrameShape(QFrame::NoFrame); - layout->addWidget(m_view); + layout->addWidget(m_view, 1, 0); + + + connect(pCore->projectManager(), SIGNAL(projectOpened(Project*)), this, SLOT(setProject(Project*))); } TimelineWidget::~TimelineWidget() { delete m_scene; - delete m_view; } void TimelineWidget::setProject(Project* project) diff --git a/src/core/timelineview/timelinewidget.h b/src/core/timelineview/timelinewidget.h index e144abe..02c731c 100644 --- a/src/core/timelineview/timelinewidget.h +++ b/src/core/timelineview/timelinewidget.h @@ -15,6 +15,7 @@ the Free Software Foundation, either version 3 of the License, or class Project; class TimelineScene; +class TimelinePositionBar; class QGraphicsView; @@ -26,6 +27,7 @@ public: explicit TimelineWidget(QWidget* parent = 0); virtual ~TimelineWidget(); +public slots: void setProject(Project *project); TimelineScene *scene(); @@ -34,6 +36,7 @@ public: private: TimelineScene *m_scene; QGraphicsView *m_view; + TimelinePositionBar *m_positionBar; }; #endif |