File indexing completed on 2024-04-14 04:46:20

0001 /*
0002     SPDX-FileCopyrightText: 2008 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003 
0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "markerdialog.h"
0008 
0009 #include "bin/model/markerlistmodel.hpp"
0010 #include "bin/projectclip.h"
0011 #include "core.h"
0012 #include "doc/kthumb.h"
0013 #include "kdenlivesettings.h"
0014 #include "project/projectmanager.h"
0015 
0016 #include "kdenlive_debug.h"
0017 #include <QFontDatabase>
0018 #include <QPushButton>
0019 #include <QTimer>
0020 #include <QWheelEvent>
0021 
0022 #include "klocalizedstring.h"
0023 
0024 MarkerDialog::MarkerDialog(ProjectClip *clip, const CommentedTime &t, const QString &caption, bool allowMultipleMarksers, QWidget *parent)
0025     : QDialog(parent)
0026     , m_clip(clip)
0027 {
0028     setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
0029     setupUi(this);
0030     setWindowTitle(caption);
0031 
0032     // Set  up categories
0033     marker_category->setCurrentCategory(t.markerType());
0034 
0035     m_in->setValue(t.time());
0036     if (!allowMultipleMarksers) {
0037         multimarker_box->setVisible(false);
0038     }
0039     interval->setValue(GenTime(KdenliveSettings::multipleguidesinterval()));
0040     m_previewTimer = new QTimer(this);
0041 
0042     if (m_clip != nullptr) {
0043         m_in->setRange(0, m_clip->getFramePlaytime());
0044         m_previewTimer->setInterval(100);
0045         connect(m_previewTimer, &QTimer::timeout, this, &MarkerDialog::slotUpdateThumb);
0046         int width = int(200 * pCore->getCurrentDar());
0047         QPixmap p(width, 200);
0048         p.fill(Qt::transparent);
0049         switch (m_clip->clipType()) {
0050         case ClipType::Video:
0051         case ClipType::AV:
0052         case ClipType::SlideShow:
0053         case ClipType::Playlist:
0054             QTimer::singleShot(0, this, &MarkerDialog::slotUpdateThumb);
0055             connect(this, &MarkerDialog::updateThumb, m_previewTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
0056             break;
0057         case ClipType::Image:
0058         case ClipType::Text:
0059         case ClipType::QText:
0060         case ClipType::Color:
0061             QTimer::singleShot(0, this, &MarkerDialog::slotUpdateThumb);
0062             // p = m_clip->pixmap(m_in->getValue(), width, height);
0063             break;
0064         // UNKNOWN, AUDIO, VIRTUAL:
0065         default:
0066             p.fill(Qt::black);
0067         }
0068 
0069         if (!p.isNull()) {
0070             clip_thumb->setScaledContents(true);
0071             clip_thumb->setPixmap(p);
0072         }
0073         connect(m_in, &TimecodeDisplay::timeCodeEditingFinished, this, &MarkerDialog::updateThumb);
0074     } else {
0075         clip_thumb->setHidden(true);
0076         label_category->setHidden(true);
0077     }
0078 
0079     marker_comment->setText(t.comment());
0080     marker_comment->selectAll();
0081     marker_comment->setFocus();
0082 
0083     buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled(marker_category->count() > 1);
0084     adjustSize();
0085 }
0086 
0087 MarkerDialog::~MarkerDialog()
0088 {
0089     delete m_previewTimer;
0090 }
0091 
0092 void MarkerDialog::slotUpdateThumb()
0093 {
0094     m_previewTimer->stop();
0095     int pos = m_in->getValue();
0096     const QPixmap p = m_clip->pixmap(pos);
0097     if (!p.isNull()) {
0098         clip_thumb->setFixedSize(p.width(), p.height());
0099         clip_thumb->setPixmap(p);
0100     } else {
0101         qCDebug(KDENLIVE_LOG) << "!!!!!!!!!!!  ERROR CREATING THUMB";
0102     }
0103 }
0104 
0105 QImage MarkerDialog::markerImage() const
0106 {
0107     return clip_thumb->pixmap(Qt::ReturnByValue).toImage();
0108 }
0109 
0110 CommentedTime MarkerDialog::newMarker()
0111 {
0112     KdenliveSettings::setDefault_marker_type(marker_category->currentCategory());
0113     return CommentedTime(m_in->gentime(), marker_comment->text(), marker_category->currentCategory());
0114 }
0115 
0116 GenTime MarkerDialog::getInterval() const
0117 {
0118     return interval->gentime();
0119 }
0120 
0121 int MarkerDialog::getOccurrences() const
0122 {
0123     return occurrences->value();
0124 }
0125 
0126 bool MarkerDialog::addMultiMarker() const
0127 {
0128     return multimarker_box->isExpanded();
0129 }