Commit dd3ca408 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Ensure markers are properly sorted in Clip Properties dialog, enable F2 rename

Related to #1143
parent 69434fb8
......@@ -3967,6 +3967,17 @@ void Bin::setBinEffectsEnabled(bool enabled, bool refreshMonitor)
void Bin::slotRenameItem()
{
if (!hasFocus() && !m_itemView->hasFocus()) {
QWidget *widget = QApplication::focusWidget();
while ((widget != nullptr) && widget != pCore->window()) {
if (widget == pCore->bin()->clipPropertiesDock()) {
for (QWidget *w : m_propertiesPanel->findChildren<ClipPropertiesController *>()) {
static_cast<ClipPropertiesController *>(w)->slotEditMarker();
break;
}
return;
}
widget = widget->parentWidget();
}
return;
}
const QModelIndexList indexes = m_proxyModel->selectionModel()->selectedRows(0);
......
......@@ -68,6 +68,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QButtonGroup>
#include <QVBoxLayout>
#include <QResizeEvent>
#include <QSortFilterProxyModel>
ElidedLinkLabel::ElidedLinkLabel(QWidget *parent)
: QLabel(parent)
......@@ -262,9 +263,13 @@ ClipPropertiesController::ClipPropertiesController(ClipController *controller, Q
m_markerTree->setAlternatingRowColors(true);
m_markerTree->setHeaderHidden(true);
m_markerTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_markerTree->setModel(controller->getMarkerModel().get());
m_markerTree->setObjectName("markers_list");
mBox->addWidget(m_markerTree);
m_sortMarkers = std::make_unique<QSortFilterProxyModel>(this);
m_sortMarkers->setSourceModel(controller->getMarkerModel().get());
m_sortMarkers->setSortRole(MarkerListModel::PosRole);
m_sortMarkers->sort(0, Qt::AscendingOrder);
m_markerTree->setModel(m_sortMarkers.get());
auto *bar = new QToolBar;
bar->addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add marker"), this, SLOT(slotAddMarker()));
bar->addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18n("Delete marker"), this, SLOT(slotDeleteMarker()));
......@@ -274,7 +279,9 @@ ClipPropertiesController::ClipPropertiesController(ClipController *controller, Q
mBox->addWidget(bar);
m_markersPage->setLayout(mBox);
connect(m_markerTree, &QAbstractItemView::doubleClicked, this, &ClipPropertiesController::slotSeekToMarker);
connect(m_markerTree, &QAbstractItemView::activated, this, &ClipPropertiesController::slotSeekToMarker);
connect(m_markerTree, &QAbstractItemView::clicked, this, &ClipPropertiesController::slotSeekToMarker);
connect(m_markerTree, &QAbstractItemView::doubleClicked, this, &ClipPropertiesController::slotEditMarker);
// metadata
auto *m2Box = new QVBoxLayout;
......@@ -1378,7 +1385,7 @@ void ClipPropertiesController::fillProperties()
void ClipPropertiesController::slotSeekToMarker()
{
auto markerModel = m_controller->getMarkerModel();
auto current = m_markerTree->currentIndex();
auto current = m_sortMarkers->mapToSource(m_markerTree->currentIndex());
if (!current.isValid()) return;
GenTime pos(markerModel->data(current, MarkerListModel::PosRole).toDouble());
emit seekToFrame(pos.frames(pCore->getCurrentFps()));
......@@ -1387,7 +1394,7 @@ void ClipPropertiesController::slotSeekToMarker()
void ClipPropertiesController::slotEditMarker()
{
auto markerModel = m_controller->getMarkerModel();
auto current = m_markerTree->currentIndex();
auto current = m_sortMarkers->mapToSource(m_markerTree->currentIndex());
if (!current.isValid()) return;
GenTime pos(markerModel->data(current, MarkerListModel::PosRole).toDouble());
markerModel->editMarkerGui(pos, this, false, m_controller);
......@@ -1397,8 +1404,12 @@ void ClipPropertiesController::slotDeleteMarker()
{
auto markerModel = m_controller->getMarkerModel();
QModelIndexList indexes = m_markerTree->selectionModel()->selectedIndexes();
QList <GenTime> positions;
QModelIndexList mapped;
for (auto &ix : indexes) {
mapped << m_sortMarkers->mapToSource(ix);
}
QList <GenTime> positions;
for (auto &ix : mapped) {
if (ix.isValid()) {
positions << GenTime(markerModel->data(ix, MarkerListModel::PosRole).toDouble());
}
......
......@@ -40,6 +40,7 @@ class QGroupBox;
class QCheckBox;
class QButtonGroup;
class QSpinBox;
class QSortFilterProxyModel;
class ElidedLinkLabel : public QLabel
{
......@@ -93,6 +94,7 @@ public slots:
void slotDeleteSelectedMarkers();
void slotSelectAllMarkers();
void updateStreamInfo(int streamIndex);
void slotEditMarker();
private slots:
void slotColorModified(const QColor &newcolor);
......@@ -100,7 +102,6 @@ private slots:
void slotEnableForce(int state);
void slotValueChanged(double);
void slotSeekToMarker();
void slotEditMarker();
void slotDeleteMarker();
void slotAddMarker();
void slotLoadMarkers();
......@@ -135,6 +136,7 @@ private:
QWidget *m_analysisPage;
QComboBox *m_audioStream;
QTreeView *m_markerTree;
std::unique_ptr<QSortFilterProxyModel>m_sortMarkers;
AnalysisTree *m_analysisTree;
QTextEdit *m_textEdit;
QListWidget *m_audioStreamsView;
......
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