29 from PyQt5.QtCore import QSize, Qt, QCoreApplication, QPointF, QRect, QRectF, QMutex, QTimer
34 from classes.logger
import log
35 from classes.app
import get_app
36 from classes.query
import Clip
41 import simplejson
as json
54 painter = QPainter(self)
55 painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing,
True)
58 painter.fillRect(event.rect(), self.palette().window())
64 pixSize.scale(event.rect().size(), Qt.KeepAspectRatio)
67 scaledPix = self.
current_image.scaled(pixSize, Qt.KeepAspectRatio, Qt.SmoothTransformation)
71 painter.drawImage(center, scaledPix)
76 fps =
get_app().project.get([
"fps"])
77 fps_float = float(fps[
"num"]) / float(fps[
"den"])
81 position_of_clip = (float(self.
transforming_clip.data[
"position"]) * fps_float) + 1
82 playhead_position = float(
get_app().window.preview_thread.current_frame)
83 clip_frame_number = round(playhead_position - position_of_clip) + start_of_clip + 1
89 player_width = self.rect().width()
90 player_height = self.rect().height()
95 source_size = QSize(source_width, source_height)
99 if scale == openshot.SCALE_FIT:
100 source_size.scale(player_width, player_height, Qt.KeepAspectRatio)
102 elif scale == openshot.SCALE_STRETCH:
103 source_size.scale(player_width, player_height, Qt.IgnoreAspectRatio)
105 elif scale == openshot.SCALE_CROP:
106 width_size = QSize(player_width, round(player_width / (float(source_width) / float(source_height))))
107 height_size = QSize(round(player_height / (float(source_height) / float(source_width))), player_height)
108 if width_size.width() >= player_width
and width_size.height() >= player_height:
109 source_size.scale(width_size.width(), width_size.height(), Qt.KeepAspectRatio)
111 source_size.scale(height_size.width(), height_size.height(), Qt.KeepAspectRatio)
114 source_width = source_size.width()
115 source_height = source_size.height()
122 sx = max(float(raw_properties.get(
'scale_x').get(
'value')), 0.001)
123 sy = max(float(raw_properties.get(
'scale_y').get(
'value')), 0.001)
124 scaled_source_width = source_width * sx
125 scaled_source_height = source_height * sy
129 if gravity == openshot.GRAVITY_TOP_LEFT:
132 elif gravity == openshot.GRAVITY_TOP:
133 x = (player_width - scaled_source_width) / 2.0
135 elif gravity == openshot.GRAVITY_TOP_RIGHT:
136 x = player_width - scaled_source_width
139 elif gravity == openshot.GRAVITY_LEFT:
140 y = (player_height - scaled_source_height) / 2.0
142 elif gravity == openshot.GRAVITY_CENTER:
143 x = (player_width - scaled_source_width) / 2.0
144 y = (player_height - scaled_source_height) / 2.0
145 elif gravity == openshot.GRAVITY_RIGHT:
146 x = player_width - scaled_source_width
147 y = (player_height - scaled_source_height) / 2.0
149 elif gravity == openshot.GRAVITY_BOTTOM_LEFT:
150 y = (player_height - scaled_source_height)
153 elif gravity == openshot.GRAVITY_BOTTOM:
154 x = (player_width - scaled_source_width) / 2.0
155 y = (player_height - scaled_source_height)
157 elif gravity == openshot.GRAVITY_BOTTOM_RIGHT:
158 x = player_width - scaled_source_width
159 y = (player_height - scaled_source_height)
167 final_size = QSize(source_width, source_height)
170 x_offset = raw_properties.get(
'location_x').get(
'value')
171 y_offset = raw_properties.get(
'location_y').get(
'value')
172 x += (scaledPix.width() * x_offset)
173 y += (scaledPix.height() * y_offset)
186 shear_x = raw_properties.get(
'shear_x').get(
'value')
187 shear_y = raw_properties.get(
'shear_y').get(
'value')
188 if shear_x
or shear_y:
192 rotation = raw_properties.get(
'rotation').get(
'value')
194 origin_x = x - self.
centeredViewport(self.width(), self.height()).x() + (scaled_source_width / 2.0)
195 origin_y = y - self.
centeredViewport(self.width(), self.height()).y() + (scaled_source_height / 2.0)
196 self.
transform.translate(origin_x, origin_y)
198 self.
transform.translate(-origin_x, -origin_y)
215 painter.fillRect(self.
topLeftHandle, QBrush(QColor(
"#53a0ed")))
221 self.
topHandle = QRectF(0.0 + (source_width / 2.0) - (cs/sx/2.0), 0, cs/sx, cs/sy)
222 self.
bottomHandle = QRectF(0.0 + (source_width / 2.0) - (cs/sx/2.0), source_height - (cs/sy), cs/sx, cs/sy)
223 self.
leftHandle = QRectF(0.0, (source_height / 2.0) - (cs/sy/2.0), cs/sx, cs/sy)
224 self.
rightHandle = QRectF(source_width - (cs/sx), (source_height / 2.0) - (cs/sy/2.0), cs/sx, cs/sy)
227 painter.fillRect(self.
topHandle, QBrush(QColor(
"#53a0ed")))
228 painter.fillRect(self.
bottomHandle, QBrush(QColor(
"#53a0ed")))
229 painter.fillRect(self.
leftHandle, QBrush(QColor(
"#53a0ed")))
230 painter.fillRect(self.
rightHandle, QBrush(QColor(
"#53a0ed")))
233 self.
centerHandle = QRectF((source_width / 2.0) - (os/sx), (source_height / 2.0) - (os/sy), os/sx*2.0, os/sy*2.0)
236 painter.setBrush(QColor(83, 160, 237, 122))
237 painter.setPen(Qt.NoPen)
241 self.
clipRect = QRectF(0, 0, final_size.width(), final_size.height())
244 painter.resetTransform()
262 heightFromWidth = width / aspectRatio
263 widthFromHeight = height * aspectRatio
265 if heightFromWidth <= height:
266 return QRect(0, (height - heightFromWidth) / 2, width, heightFromWidth)
268 return QRect((width - widthFromHeight) / 2.0, 0, widthFromHeight, height)
283 renderer.present.connect(self.
present)
294 get_app().updates.ignore_history =
True 304 get_app().updates.ignore_history =
False 323 fps =
get_app().project.get([
"fps"])
324 fps_float = float(fps[
"num"]) / float(fps[
"den"])
330 playhead_position = float(
get_app().window.preview_thread.current_frame) / fps_float
341 self.setCursor(QCursor(Qt.SizeBDiagCursor))
347 self.setCursor(QCursor(Qt.SizeVerCursor))
353 self.setCursor(QCursor(Qt.SizeFDiagCursor))
359 self.setCursor(QCursor(Qt.SizeHorCursor))
365 self.setCursor(QCursor(Qt.SizeHorCursor))
371 self.setCursor(QCursor(Qt.SizeBDiagCursor))
377 self.setCursor(QCursor(Qt.SizeVerCursor))
383 self.setCursor(QCursor(Qt.SizeFDiagCursor))
389 self.setCursor(QCursor(Qt.SizeAllCursor))
400 self.setCursor(QCursor(Qt.ArrowCursor))
403 start_of_clip_frame = round(float(self.
transforming_clip.data[
"start"]) * fps_float) + 1
404 position_of_clip_frame = (float(self.
transforming_clip.data[
"position"]) * fps_float) + 1
405 playhead_position_frame = float(
get_app().window.preview_thread.current_frame)
406 clip_frame_number = round(playhead_position_frame - position_of_clip_frame) + start_of_clip_frame
428 scale_x = (event.pos().x() - center_x) / (viewport_rect.width() / 2.0)
429 scale_y = (center_y - event.pos().y()) / (viewport_rect.height() / 2.0)
431 scale_x = (event.pos().x() - center_x) / (viewport_rect.width() / 2.0)
432 scale_y = (event.pos().y() - center_y) / (viewport_rect.height() / 2.0)
434 scale_x = (center_x - event.pos().x()) / (viewport_rect.width() / 2.0)
435 scale_y = (center_y - event.pos().y()) / (viewport_rect.height() / 2.0)
437 scale_x = (center_x - event.pos().x()) / (viewport_rect.width() / 2.0)
438 scale_y = (event.pos().y() - center_y) / (viewport_rect.height() / 2.0)
440 scale_y = (center_y - event.pos().y()) / (viewport_rect.height() / 2.0)
442 scale_y = (event.pos().y() - center_y) / (viewport_rect.height() / 2.0)
444 scale_x = (center_x - event.pos().x()) / (viewport_rect.width() / 2.0)
446 scale_x = (event.pos().x() - center_x) / (viewport_rect.width() / 2.0)
448 if int(QCoreApplication.instance().keyboardModifiers() & Qt.ControlModifier) > 0:
450 if scale_x
and scale_y:
482 for point
in c.data[property_key][
"Points"]:
483 log.info(
"looping points: co.X = %s" % point[
"co"][
"X"])
485 if point[
"co"][
"X"] == frame_number:
488 point[
"interpolation"] = openshot.BEZIER
489 point[
"co"][
"Y"] = float(new_value)
491 if not found_point
and new_value !=
None:
493 log.info(
"Created new point at X=%s" % frame_number)
494 c.data[property_key][
"Points"].append({
'co': {
'X': frame_number,
'Y': new_value},
'interpolation': openshot.BEZIER})
497 c.data = {property_key: c.data.get(property_key)}
505 get_app().window.refreshFrameSignal.emit()
533 clips =
get_app().window.timeline_sync.timeline.Clips()
542 get_app().window.refreshFrameSignal.emit()
543 get_app().window.propertyTableView.select_frame(
get_app().window.preview_thread.player.Position())
552 self.
win.actionPlay_trigger(event, force=
"pause")
565 QWidget.__init__(self, *args)
601 p.setColor(QPalette.Window, QColor(
"#191919"))
602 super().setPalette(p)
603 super().setAttribute(Qt.WA_OpaquePaintEvent)
604 super().setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
607 self.setMouseTracking(
True)
def get_app()
Returns the current QApplication instance of OpenShot.