File indexing completed on 2024-04-28 04:52:27
0001 /* 0002 SPDX-FileCopyrightText: 2017 Nicolas Carion 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #pragma once 0007 0008 #include <map> 0009 #include <vector> 0010 0011 /** @class SnapInterface 0012 @brief This is a base class for snap models (timeline, clips) 0013 Implements only basic functions like add or remove snap points 0014 */ 0015 class SnapInterface 0016 { 0017 public: 0018 SnapInterface(); 0019 virtual ~SnapInterface(); 0020 /** @brief Adds a snappoint at given position */ 0021 virtual void addPoint(int position) = 0; 0022 0023 /** @brief Removes a snappoint from given position */ 0024 virtual void removePoint(int position) = 0; 0025 }; 0026 0027 /** @class SnapModel 0028 @brief This class represents the snap points of the timeline. 0029 Basically, one can add or remove snap points, and query the closest snap point to a given location 0030 */ 0031 class SnapModel : public virtual SnapInterface 0032 { 0033 public: 0034 SnapModel(); 0035 0036 /** @brief Adds a snappoint at given position */ 0037 void addPoint(int position) override; 0038 0039 /** @brief Removes a snappoint from given position */ 0040 void removePoint(int position) override; 0041 0042 /** @brief Retrieves closest point. Returns -1 if there is no snappoint available */ 0043 int getClosestPoint(int position); 0044 0045 /** @brief Retrieves next snap point. Returns position if there is no snappoint available */ 0046 int getNextPoint(int position); 0047 0048 /** @brief Retrieves previous snap point. Returns 0 if there is no snappoint available */ 0049 int getPreviousPoint(int position); 0050 0051 /** @brief Ignores the given positions until unIgnore() is called 0052 You can make several call to this before unIgnoring 0053 Note that you cannot remove ignored points. 0054 @param points list of point to ignore 0055 */ 0056 void ignore(const std::vector<int> &pts); 0057 0058 /** @brief Revert ignoring 0059 */ 0060 void unIgnore(); 0061 0062 /** @brief Propose a size for the item (clip, composition,...) being resized, based on the snap points. 0063 @param in current inpoint of the item 0064 @param out current outpoint of the item 0065 @param size is the size requested before snapping 0066 @param right true if we resize the right end of the item 0067 @param maxSnapDist maximal number of frames we are allowed to snap to 0068 */ 0069 int proposeSize(int in, int out, int size, bool right, int maxSnapDist); 0070 int proposeSize(int in, int out, const std::vector<int> &boundaries, int size, bool right, int maxSnapDist); 0071 0072 // For testing only 0073 std::map<int, int> _snaps() { return m_snaps; } 0074 0075 private: 0076 /** This represents the snappoints internally. The keys are the positions and the values are the number of elements at this 0077 * position. Note that it is important that the datastructure is ordered. QMap is NOT ordered, and therefore not suitable. 0078 */ 0079 std::map<int, int> m_snaps; 0080 std::vector<int> m_ignore; 0081 };