Skip to content

Commit

Permalink
Merge pull request audacity#6409 from igorkorsukov/clipsview/zoom
Browse files Browse the repository at this point in the history
[AU4] Added change zoom and offset by mouse wheel
  • Loading branch information
igorkorsukov authored May 9, 2024
2 parents b4f60e7 + 3e8212a commit 3ff2077
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 132 deletions.
4 changes: 2 additions & 2 deletions au4/src/projectscene/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ set(MODULE_SRC

${CMAKE_CURRENT_LIST_DIR}/view/clipsview/clipslistmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/clipslistmodel.h
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/TimelineContext.cpp
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/TimelineContext.h
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/timelinecontext.cpp
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/timelinecontext.h
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/trackslistclipsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/trackslistclipsmodel.h
${CMAKE_CURRENT_LIST_DIR}/view/clipsview/waveview.cpp
Expand Down
1 change: 1 addition & 0 deletions au4/src/projectscene/projectscene.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<file>qml/Audacity/ProjectScene/clipsview/TracksClipsView.qml</file>
<file>qml/Audacity/ProjectScene/clipsview/TrackClipsItem.qml</file>
<file>qml/Audacity/ProjectScene/clipsview/ClipItem.qml</file>
<file>qml/Audacity/ProjectScene/clipsview/Timeline.qml</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion au4/src/projectscene/projectscenemodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "view/clipsview/trackslistclipsmodel.h"
#include "view/clipsview/clipslistmodel.h"
#include "view/clipsview/waveview.h"
#include "view/clipsview/TimelineContext.h"
#include "view/clipsview/timelinecontext.h"

using namespace au::projectscene;
using namespace muse::modularity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import QtQuick

import Muse.UiComponents

import Audacity.ProjectScene

Rectangle {

id: root

property alias context: timelineContext

height: 76
color: ui.theme.backgroundPrimaryColor

function onWheel(y) {
timelineContext.onWheel(y)
}

TimelineContext {
id: timelineContext
}

StyledTextLabel {
anchors.fill: parent
anchors.leftMargin: 16
text: "zoom: " + timelineContext.zoom + ", offset: " + timelineContext.offset
}

SeparatorLine { anchors.bottom: parent.bottom }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import Muse.UiComponents

import Audacity.ProjectScene

TimelineContext
{
Item {

id: root

clip: true

TracksListClipsModel {
id: tracksModel
}
Expand All @@ -16,40 +18,36 @@ TimelineContext
tracksModel.load()
}


Item {
id: header
Timeline {
id: timeline

anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right

height: 76

SeparatorLine { anchors.bottom: parent.bottom }
}

ListView {
id: tracksView
MouseArea {
anchors.fill: parent
onWheel: function(wheel) {
timeline.onWheel(wheel.angleDelta.y)
}
}

anchors.top: header.bottom
Column {
anchors.top: timeline.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom

clip: true

pixelAligned: true

flickableDirection: Flickable.VerticalFlick

model: tracksModel
delegate: TrackClipsItem {
anchors.left: parent.left
anchors.right: parent.right
height: 144
context: root
trackId: trackIdData
Repeater {
model: tracksModel
delegate: TrackClipsItem {
anchors.left: parent.left
anchors.right: parent.right
height: 144
context: timeline.context
trackId: trackIdData
}
}
}
}
97 changes: 0 additions & 97 deletions au4/src/projectscene/view/clipsview/TimelineContext.cpp

This file was deleted.

15 changes: 12 additions & 3 deletions au4/src/projectscene/view/clipsview/clipslistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ void ClipsListModel::load()
return;
}

connect(m_context, &TimelineContext::zoomChanged, this, &ClipsListModel::onTimelineContextChanged);
connect(m_context, &TimelineContext::offsetChanged, this, &ClipsListModel::onTimelineContextChanged);

beginResetModel();

m_clipList = prj->clipList(m_trackId);
Expand All @@ -34,8 +37,6 @@ void ClipsListModel::load()
emit dataChanged(idx, idx);
});

//! TODO Subscribe

endResetModel();
}

Expand All @@ -60,7 +61,7 @@ QVariant ClipsListModel::data(const QModelIndex& index, int role) const
case ClipTitleRole:
return clip.title.toQString();
case ClipWidthRole: {
qint64 width = m_context->timeToPosition(clip.endTime - clip.startTime);
qint64 width = (clip.endTime - clip.startTime) * m_context->zoom();
return width;
} break;
case ClipLeftRole: {
Expand All @@ -87,6 +88,14 @@ bool ClipsListModel::setData(const QModelIndex& index, const QVariant& value, in
return false;
}

void ClipsListModel::onTimelineContextChanged()
{
for (size_t i = 0; i < m_clipList.size(); ++i) {
QModelIndex idx = this->index(int(i));
emit dataChanged(idx, idx, { ClipWidthRole, ClipLeftRole });
}
}

bool ClipsListModel::changeClipStartTime(const QModelIndex& index, const QVariant& value)
{
au::processing::Clip& clip = m_clipList[index.row()];
Expand Down
5 changes: 4 additions & 1 deletion au4/src/projectscene/view/clipsview/clipslistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "global/async/asyncable.h"
#include "processing/processingtypes.h"

#include "TimelineContext.h"
#include "timelinecontext.h"

namespace au::projectscene {
class ClipsListModel : public QAbstractListModel, public muse::async::Asyncable
Expand Down Expand Up @@ -41,6 +41,9 @@ class ClipsListModel : public QAbstractListModel, public muse::async::Asyncable
signals:
void trackIdChanged();

private slots:
void onTimelineContextChanged();

private:

enum RoleNames {
Expand Down
Loading

0 comments on commit 3ff2077

Please sign in to comment.