Esempio n. 1
0
    def add_from_track(self, drag_event):
        """ Adds a timeable when a drag was started from a timeable on a track """
        # get the data thats needed to check for collisions
        item_data = drag_event.mimeData().data('ubicut/timeable')
        stream = QDataStream(item_data, QIODevice.ReadOnly)

        view_id = QDataStream.readString(stream).decode()
        timeable = self.__controller.get_timeable_by_id(view_id)

        self.dragged_timeable_id = view_id

        name = timeable.name
        width = timeable.width
        pos = timeable.mouse_press_pos
        group_id = timeable.group_id

        # get a list of items at the position where the timeable would be added
        start_pos = drag_event.pos().x()
        if start_pos < pos:
            return

        rect = QRectF(start_pos - pos, 0, width, self.height)
        colliding = [item for item in self.scene().items(rect)
                     if item.isVisible]

        # only add the timeable if colliding is empty
        if not colliding:
            res_left = timeable.resizable_left
            res_right = timeable.resizable_right
            file_name = timeable.model.file_name
            old_pos = timeable.x_pos

            # create new timeable
            model = TimeableModel(file_name, generate_id(), is_video=timeable.model.is_video)

            old_clip = timeable.model.clip

            # adjust the new model
            model.set_start(old_clip.Start(), is_sec=True)
            model.set_end(old_clip.End(), is_sec=True)
            model.move(start_pos - pos)

            new_id = generate_id()

            # add the timeable to the track
            self.__controller.create_timeable(
                self.num, name, width, start_pos, model, new_id, res_left=res_left,
                res_right=res_right, mouse_pos=pos, hist=False, is_drag=True)
            self.drag_from_track = True

            if group_id is not None:
                new_pos = -(old_pos - (start_pos - pos))
                self.__controller.remove_timeable_from_group(group_id, view_id)
                self.__controller.try_group_move(group_id, new_pos)
                self.__controller.add_timeable_to_group(group_id, new_id)

            # set item_dropped to True because the timeable was succesfully created
            self.item_dropped = True
    def add_clip(self, file_path, track):
        """ Gets a path to file and a track and creates a timeable """
        model = TimeableModel(file_path, generate_id())

        width = seconds_to_pos(model.clip.Duration())
        self.create_timeable(track,
                             os.path.basename(file_path),
                             width,
                             0,
                             model,
                             generate_id(),
                             hist=False)
    def split_timeable(self, view_id, res_right, width, model_end, pos):
        """
        Split the model's representation of a timeable at a specified
        time relative to the start of the timeable.

        The split will happen after the time-th frame of the timeable.
        This means that the time-th frame will belong to the first but
        not the second one of the resulting timeables.

        @param id:   The timeable's unique ID.
        @param pos:  The position at which the timeable should be split.
        @return:     Nothing.
        """
        op = CutOperation(view_id, res_right, width, model_end, pos,
                          generate_id(), generate_id(), self)
        self.__history.do_operation(op)

        self.__timeline_view.changed.emit()
    def create_group(self, ids):
        """
        Create a TimeableGroup with all timeables in ids in it.
        The group will be added to the timeline model.

        @param ids: list of ids of timeable views
        @return: Nothing
        """
        timeables = [self.get_timeable_by_id(i) for i in ids]
        self.__timeline_model.create_group(generate_id(), timeables)
Esempio n. 5
0
    def add_from_filemanager(self, drag_event):
        """ Adds a timeable when item from filemanager is dragged into the track """
        # get the path from the dropped item
        item_data = drag_event.mimeData().data('ubicut/file')
        stream = QDataStream(item_data, QIODevice.ReadOnly)
        path = QDataStream.readString(stream).decode()
        width = QDataStream.readInt(stream)

        x_pos = drag_event.pos().x()

        # check if theres already another timeable at the drop position
        rect = QRectF(x_pos, 0, width, self.height)
        colliding = self.scene().items(rect)
        # add the timeable when there are no colliding items
        if not colliding:
            name = os.path.basename(path)

            clip_id = generate_id()

            if Settings.get_instance().get_dict_settings()["general"]["autoaudio"]["current"]:
                model = TimeableModel(path, generate_id(), is_video=True)
                model.move(x_pos)
                model.set_end(width)
                self.__controller.create_timeable(self.num, name, width, x_pos,
                                                  model, clip_id, is_drag=True)

                model_audio = TimeableModel(path, generate_id(), is_video=False)
                model_audio.move(x_pos)
                model_audio.set_end(width)
                clip_id_audio = generate_id()
                self.__controller.create_timeable(None, name, width, x_pos, model_audio,
                                                  clip_id_audio, is_drag=True, auto_audio=self.num)

                self.__controller.create_group([clip_id, clip_id_audio])
            else:
                model_withoutgroup = TimeableModel(path, generate_id())
                model_withoutgroup.move(x_pos)
                model_withoutgroup.set_end(width)

                self.__controller.create_timeable(self.num, name, width, x_pos,
                                                  model_withoutgroup, clip_id, is_drag=True)

            self.item_dropped = True
    def create_autocut_timeables(self, file_path, track, data):
        """
        Creates timeables for autocut.

        @param file_path: the path to the input video
        @param track:     the track where the timeables will be added
        @param data:      a list of tuples with start and end time of the video
        """
        for start, end in data:
            model = TimeableModel(file_path, generate_id())
            model.set_start(start, is_sec=True)
            model.set_end(end, is_sec=True)
            model.move(start, is_sec=True)

            width = seconds_to_pos(model.clip.Duration())
            x_pos = seconds_to_pos(start)
            self.create_timeable(track,
                                 os.path.basename(file_path),
                                 width,
                                 x_pos,
                                 model,
                                 generate_id(),
                                 hist=False)