Commit 91dc8029 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Merge branch 'release/20.12' of invent.kde.org:multimedia/kdenlive into 2012

parents 28f5f1b4 afe60bb7
......@@ -66,14 +66,8 @@ std::shared_ptr<SubtitleModel> SubtitleModel::getModel()
return pCore->projectManager()->getSubtitleModel();
}
void SubtitleModel::parseSubtitle(const QString subPath)
{
qDebug()<<"Parsing started";
if (!subPath.isEmpty()) {
m_subtitleFilter->set("av.filename", subPath.toUtf8().constData());
}
QString filePath = m_subtitleFilter->get("av.filename");
m_subFilePath = filePath;
void SubtitleModel::importSubtitle(const QString filePath, int offset)
{
QString start,end,comment;
QString timeLine;
GenTime startPos, endPos;
......@@ -85,7 +79,7 @@ void SubtitleModel::parseSubtitle(const QString subPath)
*/
if (filePath.isEmpty())
return;
GenTime subtitleOffset(offset, pCore->getCurrentFps());
if (filePath.contains(".srt")) {
QFile srtFile(filePath);
if (!srtFile.exists() || !srtFile.open(QIODevice::ReadOnly)) {
......@@ -126,7 +120,7 @@ void SubtitleModel::parseSubtitle(const QString subPath)
}
turn++;
} else {
addSubtitle(startPos,endPos,comment);
addSubtitle(startPos + subtitleOffset, endPos + subtitleOffset, comment);
//reinitialize
comment = timeLine = "";
turn = 0; r = 0;
......@@ -219,7 +213,7 @@ void SubtitleModel::parseSubtitle(const QString subPath)
// Text
comment = dialogue[9]+ remainingStr;
//qDebug()<<"Start: "<< start << "End: "<<end << comment;
addSubtitle(startPos,endPos,comment);
addSubtitle(startPos + subtitleOffset, endPos + subtitleOffset, comment);
}
}
turn++;
......@@ -230,6 +224,18 @@ void SubtitleModel::parseSubtitle(const QString subPath)
}
assFile.close();
}
jsontoSubtitle(toJson());
}
void SubtitleModel::parseSubtitle(const QString subPath)
{
qDebug()<<"Parsing started";
if (!subPath.isEmpty()) {
m_subtitleFilter->set("av.filename", subPath.toUtf8().constData());
}
QString filePath = m_subtitleFilter->get("av.filename");
m_subFilePath = filePath;
importSubtitle(filePath);
//jsontoSubtitle(toJson());
}
......
......@@ -95,6 +95,9 @@ public:
@param newPos is new start position of subtitle
*/
void moveSubtitle(GenTime oldPos, GenTime newPos);
/** @brief Function that imports a subtitle file */
void importSubtitle(const QString filePath, int offset = 0);
/** @brief Exports the subtitle model to json */
QString toJson();
......
......@@ -81,8 +81,9 @@ KdenliveDoc::KdenliveDoc(const QUrl &url, QString projectFolder, QUndoGroup *und
, m_modified(false)
, m_documentOpenStatus(CleanProject)
, m_projectFolder(std::move(projectFolder))
, m_guideModel(new MarkerListModel(m_commandStack, this))
, m_subtitleModel(nullptr)
{
m_guideModel.reset(new MarkerListModel(m_commandStack, this));
connect(m_guideModel.get(), &MarkerListModel::modelChanged, this, &KdenliveDoc::guidesChanged);
connect(this, SIGNAL(updateCompositionMode(int)), parent, SLOT(slotUpdateCompositeAction(int)));
bool success = false;
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="kdenlive" version="195" translationDomain="kdenlive">
<kpartgui name="kdenlive" version="196" translationDomain="kdenlive">
<MenuBar>
<Menu name="file" >
<Action name="file_save"/>
......@@ -30,6 +30,7 @@
<Menu name="subtitles" ><text>Subtitles</text>
<Action name="subtitle_tool" />
<Action name="add_subtitle" />
<Action name="import_subtitle" />
</Menu>
<Separator />
<Action name="bin_view_mode" />
......
......@@ -586,6 +586,10 @@ void MainWindow::init()
timelineRulerMenu->addAction(actionCollection()->action(QStringLiteral("add_project_note")));
timelineRulerMenu->addAction(actionCollection()->action(QStringLiteral("add_subtitle")));
//Timeline subtitle menu
QMenu *timelineSubtitleMenu = new QMenu(this);
timelineSubtitleMenu->addAction(actionCollection()->action(QStringLiteral("delete_subtitle_clip")));
// Timeline headers menu
QMenu *timelineHeadersMenu = new QMenu(this);
timelineHeadersMenu->addAction(actionCollection()->action(QStringLiteral("insert_track")));
......@@ -767,7 +771,7 @@ void MainWindow::init()
#ifdef USE_JOGSHUTTLE
new JogManager(this);
#endif
getMainTimeline()->setTimelineMenu(timelineClipMenu, compositionMenu, timelineMenu, guideMenu, timelineRulerMenu, actionCollection()->action(QStringLiteral("edit_guide")), timelineHeadersMenu, thumbsMenu);
getMainTimeline()->setTimelineMenu(timelineClipMenu, compositionMenu, timelineMenu, guideMenu, timelineRulerMenu, actionCollection()->action(QStringLiteral("edit_guide")), timelineHeadersMenu, thumbsMenu , timelineSubtitleMenu);
scmanager->slotCheckActiveScopes();
// m_messageLabel->setMessage(QStringLiteral("This is a beta version. Always backup your data"), MltError);
}
......@@ -1703,6 +1707,8 @@ void MainWindow::setupActions()
addAction(QStringLiteral("delete_all_guides"), i18n("Delete All Guides"), this, SLOT(slotDeleteAllGuides()),
QIcon::fromTheme(QStringLiteral("edit-delete")));
addAction(QStringLiteral("add_subtitle"), i18n("Add Subtitle"), this, SLOT(slotAddSubtitle()), QIcon::fromTheme(QStringLiteral("list-add")), Qt::SHIFT +Qt::Key_S);
addAction(QStringLiteral("import_subtitle"), i18n("Import Subtitle File"), this, SLOT(slotImportSubtitle()), QIcon::fromTheme(QStringLiteral("list-add")));
addAction(QStringLiteral("delete_subtitle_clip"), i18n("Delete Subtitle"), this, SLOT(slotDeleteItem()), QIcon::fromTheme(QStringLiteral("edit-delete")));
m_saveAction = KStandardAction::save(pCore->projectManager(), SLOT(saveFile()), actionCollection());
m_saveAction->setIcon(QIcon::fromTheme(QStringLiteral("document-save")));
......@@ -4170,6 +4176,13 @@ void MainWindow::slotActivateTarget()
}
}
void MainWindow::resetSubtitles()
{
// Hide subtitle track
m_buttonSubtitleEditTool->setChecked(false);
getMainTimeline()->showSubtitles = false;
}
void MainWindow::slotEditSubtitle(const QString subPath)
{
std::shared_ptr<SubtitleModel> subtitleModel = pCore->currentDoc()->getSubtitleModel();
......@@ -4182,13 +4195,22 @@ void MainWindow::slotEditSubtitle(const QString subPath)
void MainWindow::slotAddSubtitle()
{
if (!getMainTimeline()->showSubtitles) {
if (pCore->currentDoc()->getSubtitleModel() == nullptr || !getMainTimeline()->showSubtitles) {
slotEditSubtitle();
m_buttonSubtitleEditTool->setChecked(true);
}
getCurrentTimeline()->controller()->addSubtitle();
}
void MainWindow::slotImportSubtitle()
{
if (pCore->currentDoc()->getSubtitleModel() == nullptr || !getMainTimeline()->showSubtitles) {
slotEditSubtitle();
m_buttonSubtitleEditTool->setChecked(true);
}
getCurrentTimeline()->controller()->importSubtitle();
}
#ifdef DEBUG_MAINW
#undef DEBUG_MAINW
#endif
......@@ -141,6 +141,9 @@ public:
/** @brief Raise (show) the project bin*/
void raiseBin();
/** @brief Hide subtitle track */
void resetSubtitles();
protected:
/** @brief Closes the window.
* @return false if the user presses "Cancel" on a confirmation dialog or
......@@ -509,7 +512,10 @@ private slots:
void slotActivateVideoTrackSequence();
/** @brief Select target for current track */
void slotActivateTarget();
/** @brief Add subtitle clip to timeline */
void slotAddSubtitle();
/** @brief Import a subtitle file */
void slotImportSubtitle();
signals:
Q_SCRIPTABLE void abortRenderJob(const QString &url);
......
......@@ -896,7 +896,32 @@ bool ArchiveWidget::processProjectFile()
// Make a copy of original project file for extra safety
QString backupPath = archive_url->url().toLocalFile() + QDir::separator() + m_name + QStringLiteral("-backup.kdenlive");
QFile source(pCore->currentDoc()->url().toLocalFile());
source.copy(backupPath);
if (!source.copy(backupPath)) {
// Error
KMessageBox::error(this, i18n("Cannot write to file %1", backupPath));
return false;
}
// Copy subtitle files if any
QString sub = pCore->currentDoc()->url().toLocalFile();
if (QFileInfo::exists(sub + QStringLiteral(".srt"))) {
QFile subFile(sub + QStringLiteral(".srt"));
backupPath = archive_url->url().toLocalFile() + QDir::separator() + QFileInfo(subFile).fileName();
if (!subFile.copy(backupPath)) {
// Error
KMessageBox::error(this, i18n("Cannot write to file %1", backupPath));
return false;
}
}
if (QFileInfo::exists(sub + QStringLiteral(".ass"))) {
QFile subFile(sub + QStringLiteral(".ass"));
backupPath = archive_url->url().toLocalFile() + QDir::separator() + QFileInfo(subFile).fileName();
if (!subFile.copy(backupPath)) {
// Error
KMessageBox::error(this, i18n("Cannot write to file %1", backupPath));
return false;
}
}
QString path = archive_url->url().toLocalFile() + QDir::separator() + m_name + QStringLiteral(".kdenlive");
QFile file(path);
......
......@@ -271,6 +271,7 @@ bool ProjectManager::closeCurrentDocument(bool saveChanges, bool quit)
disconnect(pCore->window()->getMainTimeline()->controller(), &TimelineController::durationChanged, this, &ProjectManager::adjustProjectDuration);
pCore->window()->getMainTimeline()->controller()->clipActions.clear();
pCore->window()->getMainTimeline()->controller()->prepareClose();
pCore->window()->resetSubtitles();
if (m_mainTimelineModel) {
m_mainTimelineModel->prepareClose();
}
......
......@@ -44,18 +44,12 @@ Item {
drag.minimumX: 0
onPressed: {
console.log('IT IS PRESSED')
if (mouse.button == Qt.RightButton) {
console.log('RIGHT BUTTON CLICKED')
timeline.deleteSubtitle(subtitleBase.x / timeline.scaleFactor, subtitleBase.x / timeline.scaleFactor + duration, subtitleEdit.text)
}
else {
root.autoScrolling = false
oldStartX = mouseX
oldStartFrame = subtitleBase.x
originalDuration = subtitleBase.width/timeScale
console.log("originalDuration",originalDuration)
controller.requestSubtitleSelection(model.startframe);
}
root.autoScrolling = false
oldStartX = mouseX
oldStartFrame = subtitleBase.x
originalDuration = subtitleBase.width/timeScale
console.log("originalDuration",originalDuration)
controller.requestSubtitleSelection(model.startframe);
}
onReleased: {
console.log('IT IS RELEASED')
......@@ -68,6 +62,12 @@ Item {
}
console.log("originalDuration after shifting",originalDuration)
}
onClicked: {
if (mouse.button == Qt.RightButton) {
//console.log('RIGHT BUTTON CLICKED')
root.showSubtitleClipMenu()
}
}
onDoubleClicked: {
parent.textEditBegin = true
}
......
......@@ -24,6 +24,7 @@ Rectangle {
signal zoomIn(bool onMouse)
signal zoomOut(bool onMouse)
signal processingDrag(bool dragging)
signal showSubtitleClipMenu()
FontMetrics {
id: fontMetrics
......
......@@ -50,8 +50,10 @@
#include "timeline2/view/dialogs/trackdialog.h"
#include "transitions/transitionsrepository.hpp"
#include "audiomixer/mixermanager.hpp"
#include "ui_import_subtitle_ui.h"
#include <KColorScheme>
#include <KRecentDirs>
#include <QApplication>
#include <QClipboard>
#include <QQuickItem>
......@@ -3851,6 +3853,22 @@ void TimelineController::addSubtitle(int startframe)
pCore->pushUndo(local_undo, local_redo, i18n("Add subtitle"));
}
void TimelineController::importSubtitle()
{
QPointer<QDialog> d = new QDialog;
Ui::ImportSub_UI view;
view.setupUi(d);
d->setWindowTitle(i18n("Import Subtitle"));
if (d->exec() == QDialog::Accepted && !view.subtitle_url->url().isEmpty()) {
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
int offset = 0;
if (view.cursor_pos->isChecked()) {
offset = pCore->getTimelinePosition();
}
subtitleModel->importSubtitle(view.subtitle_url->url().toLocalFile(), offset);
}
}
void TimelineController::deleteSubtitle(int startframe, int endframe, QString text)
{
auto subtitleModel = pCore->projectManager()->current()->getSubtitleModel();
......@@ -3867,5 +3885,4 @@ void TimelineController::deleteSubtitle(int startframe, int endframe, QString te
};
local_redo();
pCore->pushUndo(local_undo, local_redo, i18n("Delete subtitle"));
return;
}
......@@ -582,6 +582,8 @@ public:
Q_INVOKABLE void addSubtitle(int startframe = -1);
/** @brief Delete subtitle clip with frame as start position*/
Q_INVOKABLE void deleteSubtitle(int frameframe, int endframe, QString Ctext);
/** @brief Import a subtitle file*/
void importSubtitle();
public slots:
void resetView();
......
......@@ -115,7 +115,7 @@ const QMap<QString, QString> TimelineWidget::sortedItems(const QStringList &item
return sortedItems;
}
void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QMenu *timelineMenu, QMenu *guideMenu, QMenu *timelineRulerMenu, QAction *editGuideAction, QMenu *headerMenu, QMenu *thumbsMenu)
void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QMenu *timelineMenu, QMenu *guideMenu, QMenu *timelineRulerMenu, QAction *editGuideAction, QMenu *headerMenu, QMenu *thumbsMenu, QMenu *subtitleClipMenu)
{
m_timelineClipMenu = clipMenu;
m_timelineCompositionMenu = compositionMenu;
......@@ -125,6 +125,7 @@ void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QM
m_headerMenu = headerMenu;
m_thumbsMenu = thumbsMenu;
m_headerMenu->addMenu(m_thumbsMenu);
m_timelineSubtitleClipMenu = subtitleClipMenu;
m_editGuideAcion = editGuideAction;
updateEffectFavorites();
updateTransitionFavorites();
......@@ -146,6 +147,7 @@ void TimelineWidget::setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QM
connect(m_timelineCompositionMenu, &QMenu::aboutToHide, this, &TimelineWidget::slotUngrabHack, Qt::DirectConnection);
connect(m_timelineRulerMenu, &QMenu::aboutToHide, this, &TimelineWidget::slotUngrabHack, Qt::DirectConnection);
connect(m_timelineMenu, &QMenu::aboutToHide, this, &TimelineWidget::slotUngrabHack, Qt::DirectConnection);
connect(m_timelineSubtitleClipMenu, &QMenu::aboutToHide, this, &TimelineWidget::slotUngrabHack, Qt::DirectConnection);
m_timelineClipMenu->addMenu(m_favEffects);
m_timelineClipMenu->addMenu(m_favCompositions);
......@@ -189,6 +191,7 @@ void TimelineWidget::setModel(const std::shared_ptr<TimelineItemModel> &model, M
connect(rootObject(), SIGNAL(showRulerMenu()), this, SLOT(showRulerMenu()));
connect(rootObject(), SIGNAL(showHeaderMenu()), this, SLOT(showHeaderMenu()));
connect(rootObject(), SIGNAL(showTargetMenu(int)), this, SLOT(showTargetMenu(int)));
connect(rootObject(), SIGNAL(showSubtitleClipMenu()), this, SLOT(showSubtitleClipMenu()));
m_proxy->setRoot(rootObject());
setVisible(true);
loading = false;
......@@ -351,6 +354,11 @@ void TimelineWidget::showTimelineMenu()
m_timelineMenu->popup(m_clickPos);
}
void TimelineWidget::showSubtitleClipMenu()
{
m_timelineSubtitleClipMenu->popup(m_clickPos);
}
void TimelineWidget::slotChangeZoom(int value, bool zoomOnMouse)
{
double pixelScale = QFontMetrics(font()).maxWidth() * 2;
......@@ -490,7 +498,7 @@ void TimelineWidget::connectSubtitleModel()
{
showSubtitles = !showSubtitles;
//qDebug()<<"null ptr NOT here at root context";
rootObject()->setProperty("showSubtitles",showSubtitles);
rootObject()->setProperty("showSubtitles", showSubtitles);
rootContext()->setContextProperty("subtitleModel", pCore->projectManager()->current()->getSubtitleModel().get());
}
}
\ No newline at end of file
}
......@@ -54,7 +54,7 @@ public:
/* @brief Give keyboard focus to timeline qml */
void focusTimeline();
/** @brief Initiate timeline clip context menu */
void setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QMenu *timelineMenu, QMenu *timelineRulerMenu, QMenu *guideMenu, QAction *editGuideAction, QMenu *headerMenu, QMenu *thumbsMenu);
void setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QMenu *timelineMenu, QMenu *timelineRulerMenu, QMenu *guideMenu, QAction *editGuideAction, QMenu *headerMenu, QMenu *thumbsMenu, QMenu *subtitleClipMenu);
bool loading;
void connectSubtitleModel();
bool showSubtitles=false;
......@@ -84,6 +84,7 @@ private slots:
void showTimelineMenu();
void showRulerMenu();
void showHeaderMenu();
void showSubtitleClipMenu();
private:
TimelineController *m_proxy;
......@@ -99,6 +100,7 @@ private:
QMenu *m_favEffects;
QMenu *m_favCompositions;
QAction *m_editGuideAcion;
QMenu *m_timelineSubtitleClipMenu;
static const int comboScale[];
std::unique_ptr<QSortFilterProxyModel> m_sortModel;
/* @brief Keep last scale before fit to restore it on second click */
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportSub_UI</class>
<widget class="QDialog" name="ImportSub_UI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>383</width>
<height>204</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Subtitle file</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="KUrlRequester" name="subtitle_url">
<property name="filter">
<string>*.srt *.ass</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cursor_pos">
<property name="text">
<string>Import at timeline cursor position</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QWidget</extends>
<header>kurlrequester.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImportSub_UI</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportSub_UI</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
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