diff --git a/krita/krita.action b/krita/krita.action
index 0ba5289881..8191b2fc83 100644
--- a/krita/krita.action
+++ b/krita/krita.action
@@ -1,3640 +1,3669 @@
General
Open Resources Folder
Opens a file browser at the location Krita saves resources such as brushes to.
Opens a file browser at the location Krita saves resources such as brushes to.
Open Resources Folder
0
0
false
Cleanup removed files...
Cleanup removed files
Cleanup removed files
0
0
false
C&ascade
Cascade
Cascade
10
0
false
&Tile
Tile
Tile
10
0
false
Create Resource Bundle...
Create Resource Bundle
Create Resource Bundle
0
0
false
Show File Toolbar
Show File Toolbar
Show File Toolbar
false
Show color selector
Show color selector
Show color selector
Shift+I
false
Show MyPaint shade selector
Show MyPaint shade selector
Show MyPaint shade selector
Shift+M
false
Show minimal shade selector
Show minimal shade selector
Show minimal shade selector
Shift+N
false
Show color history
Show color history
Show color history
H
false
Show common colors
Show common colors
Show common colors
U
false
Show Tool Options
Show Tool Options
Show Tool Options
\
false
Show Brush Editor
Show Brush Editor
Show Brush Editor
F5
false
Show Brush Presets
Show Brush Presets
Show Brush Presets
F6
false
Toggle Tablet Debugger
Toggle Tablet Debugger
Toggle Tablet Debugger
0
0
Ctrl+Shift+T
false
Show system information for bug reports.
Show system information for bug reports.
Show system information for bug reports.
false
Rename Composition...
Rename Composition
Rename Composition
0
0
false
Update Composition
Update Composition
Update Composition
0
0
false
Use multiple of 2 for pixel scale
Use multiple of 2 for pixel scale
Use multiple of 2 for pixel scale
Use multiple of 2 for pixel scale
1
0
true
&Invert Selection
Invert current selection
Invert Selection
10000000000
100
Ctrl+Shift+I
false
Create Snapshot
Create Snapshot
1
0
false
Switch to Selected Snapshot
Switch to selected snapshot
1
0
false
Remove Selected Snapshot
Remove Selected Snapshot
1
0
false
Painting
lightness-increase
Make brush color lighter
Make brush color lighter
Make brush color lighter
0
0
L
false
lightness-decrease
Make brush color darker
Make brush color darker
Make brush color darker
0
0
K
false
Make brush color more saturated
Make brush color more saturated
Make brush color more saturated
false
Make brush color more desaturated
Make brush color more desaturated
Make brush color more desaturated
false
Shift brush color hue clockwise
Shift brush color hue clockwise
Shift brush color hue clockwise
false
Shift brush color hue counter-clockwise
Shift brush color hue counter-clockwise
Shift brush color hue counter-clockwise
false
Make brush color more red
Make brush color more red
Make brush color more red
false
Make brush color more green
Make brush color more green
Make brush color more green
false
Make brush color more blue
Make brush color more blue
Make brush color more blue
false
Make brush color more yellow
Make brush color more yellow
Make brush color more yellow
false
opacity-increase
Increase opacity
Increase opacity
Increase opacity
0
0
O
false
opacity-decrease
Decrease opacity
Decrease opacity
Decrease opacity
0
0
I
false
draw-eraser
Set eraser mode
Set eraser mode
Set eraser mode
10000
0
E
true
view-refresh
Reload Original Preset
Reload Original Preset
Reload Original Preset
10000
false
transparency-unlocked
Preserve Alpha
Preserve Alpha
Preserve Alpha
10000
true
transform_icons_penPressure
Use Pen Pressure
Use Pen Pressure
Use Pen Pressure
10000
true
symmetry-horizontal
Horizontal Mirror Tool
Horizontal Mirror Tool
Horizontal Mirror Tool
0
true
symmetry-vertical
Vertical Mirror Tool
Vertical Mirror Tool
Vertical Mirror Tool
0
true
Hide Mirror X Line
Hide Mirror X Line
Hide Mirror X Line
10000
true
Hide Mirror Y Line
Hide Mirror Y Line
Hide Mirror Y Line
10000
true
Lock
Lock X Line
Lock X Line
10000
true
Lock Y Line
Lock Y Line
Lock Y Line
10000
true
Move to Canvas Center
Move to Canvas Center X
Move to Canvas Center X
10000
false
Move to Canvas Center Y
Move to Canvas Center Y
Move to Canvas Center Y
10000
false
&Toggle Selection Display Mode
Toggle Selection Display Mode
Toggle Selection Display Mode
0
0
false
Next Favourite Preset
Next Favourite Preset
Next Favourite Preset
,
false
Previous Favourite Preset
Previous Favourite Preset
Previous Favourite Preset
.
false
preset-switcher
Switch to Previous Preset
Switch to Previous Preset
Switch to Previous Preset
/
false
Hide Brushes and Stuff Toolbar
Hide Brushes and Stuff Toolbar
Hide Brushes and Stuff Toolbar
true
Reset Foreground and Background Color
Reset Foreground and Background Color
Reset Foreground and Background Color
D
false
Swap Foreground and Background Color
Swap Foreground and Background Color
Swap Foreground and Background Color
X
false
Selection Mode: Add
Selection Mode: Add
Selection Mode: Add
A
false
Selection Mode: Subtract
Selection Mode: Subtract
Selection Mode: Subtract
S
false
Selection Mode: Intersect
Selection Mode: Intersect
Selection Mode: Intersect
false
Selection Mode: Replace
Selection Mode: Replace
Selection Mode: Replace
R
false
smoothing-weighted
Brush Smoothing: Weighted
Brush Smoothing: Weighted
Brush Smoothing: Weighted
false
smoothing-no
Brush Smoothing: Disabled
Brush Smoothing: Disabled
Brush Smoothing: Disabled
false
smoothing-stabilizer
Brush Smoothing: Stabilizer
Brush Smoothing: Stabilizer
Brush Smoothing: Stabilizer
false
brushsize-decrease
Decrease Brush Size
Decrease Brush Size
Decrease Brush Size
0
0
[
false
smoothing-basic
Brush Smoothing: Basic
Brush Smoothing: Basic
Brush Smoothing: Basic
false
brushsize-increase
Increase Brush Size
Increase Brush Size
Increase Brush Size
0
0
]
false
Toggle Assistant
Toggle Assistant
ToggleAssistant
Ctrl+Shift+L
true
Undo Polygon Selection Points
Undo Polygon Selection Points
Undo Polygon Selection Points
Shift+Z
false
Fill with Foreground Color (Opacity)
Fill with Foreground Color (Opacity)
Fill with Foreground Color (Opacity)
10000
1
Ctrl+Shift+Backspace
false
Fill with Background Color (Opacity)
Fill with Background Color (Opacity)
Fill with Background Color (Opacity)
10000
1
Ctrl+Backspace
false
Fill with Pattern (Opacity)
Fill with Pattern (Opacity)
Fill with Pattern (Opacity)
10000
1
false
Convert &to Shape
Convert to Shape
Convert to Shape
10000000000
0
false
&Show Global Selection Mask
Shows global selection as a usual selection mask in <interface>Layers</interface> docker
Show Global Selection Mask
100000
100
true
Filters
color-to-alpha
&Color to Alpha...
Color to Alpha
Color to Alpha
10000
0
false
&Top Edge Detection
Top Edge Detection
Top Edge Detection
10000
0
false
&Index Colors...
Index Colors
Index Colors
10000
0
false
Emboss Horizontal &Only
Emboss Horizontal Only
Emboss Horizontal Only
10000
0
false
D&odge
Dodge
Dodge
10000
0
false
&Sharpen
Sharpen
Sharpen
10000
0
false
B&urn
Burn
Burn
10000
0
false
&Mean Removal
Mean Removal
Mean Removal
10000
0
false
&Gaussian Blur...
Gaussian Blur
Gaussian Blur
10000
0
false
Emboss &in All Directions
Emboss in All Directions
Emboss in All Directions
10000
0
false
&Small Tiles...
Small Tiles
Small Tiles
10000
0
false
&Levels...
Levels
Levels
10000
0
Ctrl+L
false
&Sobel...
Sobel
Sobel
10000
0
false
&Wave...
Wave
Wave
10000
0
false
&Motion Blur...
Motion Blur
Motion Blur
10000
0
false
&Invert
Invert
Invert
10000
0
Ctrl+I
false
&Color Adjustment curves...
Color Adjustment curves
Color Adjustment curves
10000
0
Ctrl+M
false
Pi&xelize...
Pixelize
Pixelize
10000
0
false
Emboss (&Laplacian)
Emboss (Laplacian)
Emboss (Laplacian)
10000
0
false
&Left Edge Detection
Left Edge Detection
Left Edge Detection
10000
0
false
&Blur...
Blur
Blur
10000
0
false
&Raindrops...
Raindrops
Raindrops
10000
0
false
&Bottom Edge Detection
Bottom Edge Detection
Bottom Edge Detection
10000
0
false
&Random Noise...
Random Noise
Random Noise
10000
0
false
&Brightness/Contrast curve...
Brightness/Contrast curve
Brightness/Contrast curve
10000
0
false
Colo&r Balance...
Color Balance
Color Balance
10000
0
Ctrl+B
false
&Phong Bumpmap...
Phong Bumpmap
Phong Bumpmap
10000
0
false
&Desaturate
Desaturate
Desaturate
10000
0
Ctrl+Shift+U
false
Color &Transfer...
Color Transfer
Color Transfer
10000
0
false
Emboss &Vertical Only
Emboss Vertical Only
Emboss Vertical Only
10000
0
false
&Lens Blur...
Lens Blur
Lens Blur
10000
0
false
M&inimize Channel
Minimize Channel
Minimize Channel
10000
0
false
M&aximize Channel
Maximize Channel
Maximize Channel
10000
0
false
&Oilpaint...
Oilpaint
Oilpaint
10000
0
false
&Right Edge Detection
Right Edge Detection
Right Edge Detection
10000
0
false
&Auto Contrast
Auto Contrast
Auto Contrast
10000
0
false
&Round Corners...
Round Corners
Round Corners
10000
0
false
&Unsharp Mask...
Unsharp Mask
Unsharp Mask
10000
0
false
&Emboss with Variable Depth...
Emboss with Variable Depth
Emboss with Variable Depth
10000
0
false
Emboss &Horizontal && Vertical
Emboss Horizontal & Vertical
Emboss Horizontal & Vertical
10000
0
false
Random &Pick...
Random Pick
Random Pick
10000
0
false
&Gaussian Noise Reduction...
Gaussian Noise Reduction
Gaussian Noise Reduction
10000
0
false
&Posterize...
Posterize
Posterize
10000
0
false
&Wavelet Noise Reducer...
Wavelet Noise Reducer
Wavelet Noise Reducer
10000
0
false
&HSV Adjustment...
HSV Adjustment
HSV Adjustment
10000
0
Ctrl+U
false
Tool Shortcuts
Dynamic Brush Tool
Dynamic Brush Tool
Dynamic Brush Tool
false
Crop Tool
Crop the image to an area
Crop the image to an area
C
false
Polygon Tool
Polygon Tool. Shift-mouseclick ends the polygon.
Polygon Tool. Shift-mouseclick ends the polygon.
false
Rectangle Tool
Rectangle Tool
Rectangle Tool
false
Multibrush Tool
Multibrush Tool
Multibrush Tool
Q
false
Colorize Mask Tool
Colorize Mask Tool
Colorize Mask Tool
Smart Patch Tool
Smart Patch Tool
Smart Patch Tool
Pan Tool
Pan Tool
Pan Tool
Select Shapes Tool
Select Shapes Tool
Select Shapes Tool
false
Color Picker
Select a color from the image or current layer
Select a color from the image or current layer
P
false
Outline Selection Tool
Outline Selection Tool
Outline Selection Tool
false
Bezier Curve Selection Tool
Select a
Bezier Curve Selection Tool
false
Similar Color Selection Tool
Select a
Similar Color Selection Tool
false
Fill Tool
Fill a contiguous area of color with a color, or fill a selection.
Fill a contiguous area of color with a color, or fill a selection.
F
false
Line Tool
Line Tool
Line Tool
false
Freehand Path Tool
Freehand Path Tool
Freehand Path Tool
false
Bezier Curve Tool
Bezier Curve Tool. Shift-mouseclick or double-click ends the curve.
Bezier Curve Tool. Shift-mouseclick or double-click ends the curve.
false
Ellipse Tool
Ellipse Tool
Ellipse Tool
false
Freehand Brush Tool
Freehand Brush Tool
Freehand Brush Tool
B
false
Create object
Create object
Create object
false
Elliptical Selection Tool
Elliptical Selection Tool
Elliptical Selection Tool
J
false
Contiguous Selection Tool
Contiguous Selection Tool
Contiguous Selection Tool
false
Pattern editing
Pattern editing
Pattern editing
false
Review
Review
Review
false
Draw a gradient.
Draw a gradient.
Draw a gradient.
G
false
Polygonal Selection Tool
Polygonal Selection Tool
Polygonal Selection Tool
false
Measurement Tool
Measure the distance between two points
Measure the distance between two points
false
Rectangular Selection Tool
Rectangular Selection Tool
Rectangular Selection Tool
Ctrl+R
false
Move Tool
Move a layer
Move a layer
T
false
Vector Image Tool
Vector Image (EMF/WMF/SVM/SVG) tool
Vector Image (EMF/WMF/SVM/SVG) tool
false
Calligraphy
Calligraphy
Calligraphy
false
Path editing
Path editing
Path editing
false
Zoom Tool
Zoom Tool
Zoom Tool
false
Polyline Tool
Polyline Tool. Shift-mouseclick ends the polyline.
Polyline Tool. Shift-mouseclick ends the polyline.
false
Transform Tool
Transform a layer or a selection
Transform a layer or a selection
Ctrl+T
false
Assistant Tool
Assistant Tool
Assistant Tool
false
Gradient Editing Tool
Gradient editing
Gradient editing
false
Reference Images Tool
Reference Images Tool
Reference Images Tool
false
Blending Modes
Select Normal Blending Mode
Select Normal Blending Mode
Select Normal Blending Mode
0
0
Alt+Shift+N
false
Select Dissolve Blending Mode
Select Dissolve Blending Mode
Select Dissolve Blending Mode
0
0
Alt+Shift+I
false
Select Behind Blending Mode
Select Behind Blending Mode
Select Behind Blending Mode
0
0
Alt+Shift+Q
false
Select Clear Blending Mode
Select Clear Blending Mode
Select Clear Blending Mode
0
0
Alt+Shift+R
false
Select Darken Blending Mode
Select Darken Blending Mode
Select Darken Blending Mode
0
0
Alt+Shift+K
false
Select Multiply Blending Mode
Select Multiply Blending Mode
Select Multiply Blending Mode
0
0
Alt+Shift+M
false
Select Color Burn Blending Mode
Select Color Burn Blending Mode
Select Color Burn Blending Mode
0
0
Alt+Shift+B
false
Select Linear Burn Blending Mode
Select Linear Burn Blending Mode
Select Linear Burn Blending Mode
0
0
Alt+Shift+A
false
Select Lighten Blending Mode
Select Lighten Blending Mode
Select Lighten Blending Mode
0
0
Alt+Shift+G
false
Select Screen Blending Mode
Select Screen Blending Mode
Select Screen Blending Mode
0
0
Alt+Shift+S
false
Select Color Dodge Blending Mode
Select Color Dodge Blending Mode
Select Color Dodge Blending Mode
0
0
Alt+Shift+D
false
Select Linear Dodge Blending Mode
Select Linear Dodge Blending Mode
Select Linear Dodge Blending Mode
0
0
Alt+Shift+W
false
Select Overlay Blending Mode
Select Overlay Blending Mode
Select Overlay Blending Mode
0
0
Alt+Shift+O
false
Select Hard Overlay Blending Mode
Select Hard Overlay Blending Mode
Select Hard Overlay Blending Mode
0
0
Alt+Shift+P
false
Select Soft Light Blending Mode
Select Soft Light Blending Mode
Select Soft Light Blending Mode
0
0
Alt+Shift+F
false
Select Hard Light Blending Mode
Select Hard Light Blending Mode
Select Hard Light Blending Mode
0
0
Alt+Shift+H
false
Select Vivid Light Blending Mode
Select Vivid Light Blending Mode
Select Vivid Light Blending Mode
0
0
Alt+Shift+V
false
Select Linear Light Blending Mode
Select Linear Light Blending Mode
Select Linear Light Blending Mode
0
0
Alt+Shift+J
false
Select Pin Light Blending Mode
Select Pin Light Blending Mode
Select Pin Light Blending Mode
0
0
Alt+Shift+Z
false
Select Hard Mix Blending Mode
Select Hard Mix Blending Mode
Select Hard Mix Blending Mode
0
0
Alt+Shift+L
false
Select Difference Blending Mode
Select Difference Blending Mode
Select Difference Blending Mode
0
0
Alt+Shift+E
false
Select Exclusion Blending Mode
Select Exclusion Blending Mode
Select Exclusion Blending Mode
0
0
Alt+Shift+X
false
Select Hue Blending Mode
Select Hue Blending Mode
Select Hue Blending Mode
0
0
Alt+Shift+U
false
Select Saturation Blending Mode
Select Saturation Blending Mode
Select Saturation Blending Mode
0
0
Alt+Shift+T
false
Select Color Blending Mode
Select Color Blending Mode
Select Color Blending Mode
0
0
Alt+Shift+C
false
Select Luminosity Blending Mode
Select Luminosity Blending Mode
Select Luminosity Blending Mode
0
0
Alt+Shift+Y
false
Animation
Previous frame
Move to previous frame
Move to previous frame
1
0
false
Next frame
Move to next frame
Move to next frame
1
0
false
Play / pause animation
Play / pause animation
Play / pause animation
1
0
false
addblankframe
Create Blank Frame
Add blank frame
Add blank frame
100000
0
false
addduplicateframe
Create Duplicate Frame
Add duplicate frame
Add duplicate frame
100000
0
false
Toggle onion skin
Toggle onion skin
Toggle onion skin
100000
0
false
Previous Keyframe
false
Next Keyframe
false
First Frame
false
Last Frame
false
Auto Frame Mode
true
true
Show in Timeline
true
Insert Keyframe Left
Insert keyframes to the left of selection, moving the tail of animation to the right.
100000
0
false
Insert Keyframe Right
Insert keyframes to the right of selection, moving the tail of animation to the right.
100000
0
false
Insert Multiple Keyframes
Insert several keyframes based on user parameters.
100000
0
false
Remove Frame and Pull
Remove keyframes moving the tail of animation to the left
100000
0
false
deletekeyframe
Remove Keyframe
Remove keyframes without moving anything around
100000
0
false
Insert Column Left
Insert column to the left of selection, moving the tail of animation to the right
100000
0
false
Insert Column Right
Insert column to the right of selection, moving the tail of animation to the right
100000
0
false
Insert Multiple Columns
Insert several columns based on user parameters.
100000
0
false
Remove Column and Pull
Remove columns moving the tail of animation to the left
100000
0
false
Remove Column
Remove columns without moving anything around
100000
0
false
Insert Hold Frame
Insert a hold frame after every keyframe
100000
0
false
Insert Multiple Hold Frames
Insert N hold frames after every keyframe
100000
0
false
Remove Hold Frame
Remove a hold frame after every keyframe
100000
0
false
Remove Multiple Hold Frames
Remove N hold frames after every keyframe
100000
0
false
Insert Hold Column
Insert a hold column into the frame at the current position
100000
0
false
Insert Multiple Hold Columns
Insert N hold columns into the frame at the current position
100000
0
false
Remove Hold Column
Remove a hold column from the frame at the current position
100000
0
false
Remove Multiple Hold Columns
Remove N hold columns from the frame at the current position
100000
0
false
+
+
+
+ Add opacity keyframe
+
+ Adds keyframe to control layer opacity
+
+ 100000
+ 0
+
+ false
+
+
+
+
+
+
+ Remove opacity keyframe
+
+ Removes keyframe to control layer opacity
+
+ 100000
+ 0
+
+ false
+
+
+
+
Mirror Frames
Mirror frames' position
100000
0
false
Mirror Columns
Mirror columns' position
100000
0
false
Copy to Clipboard
Copy frames to clipboard
100000
0
false
Cut to Clipboard
Cut frames to clipboard
100000
0
false
Paste from Clipboard
Paste frames from clipboard
100000
0
false
Copy Columns to Clipboard
Copy columns to clipboard
100000
0
false
Cut Columns to Clipboard
Cut columns to clipboard
100000
0
false
Paste Columns from Clipboard
Paste columns from clipboard
100000
0
false
Set Start Time
100000
0
false
Set End Time
100000
0
false
Update Playback Range
100000
0
false
Layers
Activate next layer
Activate next layer
Activate next layer
1000
0
PgUp
false
Activate previous layer
Activate previous layer
Activate previous layer
1000
0
PgDown
false
Activate previously selected layer
Activate previously selected layer
Activate previously selected layer
1000
0
;
false
groupLayer
&Group Layer
Group Layer
Group Layer
1000
0
false
cloneLayer
&Clone Layer
Clone Layer
Clone Layer
1000
0
false
vectorLayer
&Vector Layer
Vector Layer
Vector Layer
1000
0
false
filterLayer
&Filter Layer...
Filter Layer
Filter Layer
1000
0
false
fillLayer
&Fill Layer...
Fill Layer
Fill Layer
1000
0
false
fileLayer
&File Layer...
File Layer
File Layer
1000
0
false
transparencyMask
&Transparency Mask
Transparency Mask
Transparency Mask
100000
0
false
filterMask
&Filter Mask...
Filter Mask
Filter Mask
100000
0
false
filterMask
&Colorize Mask
Colorize Mask
Colorize Mask
100000
0
false
transformMask
&Transform Mask...
Transform Mask
Transform Mask
100000
0
false
selectionMask
&Local Selection
Local Selection
Local Selection
100000
0
false
view-filter
&Isolate Layer
Isolate Layer
Isolate Layer
1000
0
true
layer-locked
&Toggle layer lock
Toggle layer lock
Toggle layer lock
1000
0
false
visible
Toggle layer &visibility
Toggle layer visibility
Toggle layer visibility
1000
0
false
transparency-locked
Toggle layer &alpha
Toggle layer alpha
Toggle layer alpha
1000
0
false
transparency-enabled
Toggle layer alpha &inheritance
Toggle layer alpha inheritance
Toggle layer alpha inheritance
1000
0
false
paintLayer
&Paint Layer
Paint Layer
Paint Layer
1000
0
Insert
false
&New Layer From Visible
New layer from visible
New layer from visible
1000
0
false
duplicatelayer
&Duplicate Layer or Mask
Duplicate Layer or Mask
Duplicate Layer or Mask
1000
0
Ctrl+J
false
&Cut Selection to New Layer
Cut Selection to New Layer
Cut Selection to New Layer
100000000
1
Ctrl+Shift+J
false
Copy &Selection to New Layer
Copy Selection to New Layer
Copy Selection to New Layer
100000000
0
Ctrl+Alt+J
false
Copy Layer
Copy layer to clipboard
Copy layer to clipboard
1000
0
false
Cut Layer
Cut layer to clipboard
Cut layer to clipboard
1000
0
false
Paste Layer
Paste layer from clipboard
Paste layer from clipboard
1000
0
false
Quick Group
Create a group layer containing selected layers
Quick Group
1000
0
Ctrl+G
false
Quick Ungroup
Remove grouping of the layers or remove one layer out of the group
Quick Ungroup
100000
0
Ctrl+Alt+G
false
Quick Clipping Group
Group selected layers and add a layer with clipped alpha channel
Quick Clipping Group
100000
0
Ctrl+Shift+G
false
All Layers
Select all layers
Select all layers
10000
0
false
Visible Layers
Select all visible layers
Select all visible layers
10000
0
false
Locked Layers
Select all locked layers
Select all locked layers
10000
0
false
Invisible Layers
Select all invisible layers
Select all invisible layers
10000
0
false
Unlocked Layers
Select all unlocked layers
Select all unlocked layers
10000
0
false
document-save
&Save Layer/Mask...
Save Layer/Mask
Save Layer/Mask
1000
0
false
document-save
Save Vector Layer as SVG...
Save Vector Layer as SVG
Save Vector Layer as SVG
1000
0
false
document-save
Save &Group Layers...
Save Group Layers
Save Group Layers
100000
0
false
Convert group to &animated layer
Convert child layers into animation frames
Convert child layers into animation frames
100000
0
false
fileLayer
to &File Layer
Saves out the layers into a new image and then references that image.
Convert to File Layer
100000
0
false
I&mport Layer...
Import Layer
Import Layer
100000
0
false
paintLayer
&as Paint Layer...
as Paint Layer
as Paint Layer
1000
0
false
transparencyMask
as &Transparency Mask...
as Transparency Mask
as Transparency Mask
1000
0
false
filterMask
as &Filter Mask...
as Filter Mask
as Filter Mask
1000
0
false
selectionMask
as &Selection Mask...
as Selection Mask
as Selection Mask
1000
0
false
paintLayer
to &Paint Layer
to Paint Layer
to Paint Layer
1000
0
false
transparencyMask
to &Transparency Mask
to Transparency Mask
to Transparency Mask
1000
0
false
filterMask
to &Filter Mask...
to Filter Mask
to Filter Mask
1000
0
false
selectionMask
to &Selection Mask
to Selection Mask
to Selection Mask
1000
0
false
transparencyMask
&Alpha into Mask
Alpha into Mask
Alpha into Mask
100000
10
false
transparency-enabled
&Write as Alpha
Write as Alpha
Write as Alpha
1000000
1
false
document-save
&Save Merged...
Save Merged
Save Merged
1000000
0
false
split-layer
Split Layer...
Split Layer
Split Layer
1000
0
false
Wavelet Decompose ...
Wavelet Decompose
Wavelet Decompose
1000
1
false
symmetry-horizontal
Mirror Layer Hori&zontally
Mirror Layer Horizontally
Mirror Layer Horizontally
1000
1
false
symmetry-vertical
Mirror Layer &Vertically
Mirror Layer Vertically
Mirror Layer Vertically
1000
1
false
&Rotate Layer...
Rotate Layer
Rotate Layer
1000
1
false
object-rotate-right
Rotate &Layer 90° to the Right
Rotate Layer 90° to the Right
Rotate Layer 90° to the Right
1000
1
false
object-rotate-left
Rotate Layer &90° to the Left
Rotate Layer 90° to the Left
Rotate Layer 90° to the Left
1000
1
false
Rotate Layer &180°
Rotate Layer 180°
Rotate Layer 180°
1000
1
false
Scale &Layer to new Size...
Scale Layer to new Size
Scale Layer to new Size
100000
1
false
&Shear Layer...
Shear Layer
Shear Layer
1000
1
false
symmetry-horizontal
Mirror All Layers Hori&zontally
Mirror All Layers Horizontally
Mirror All Layers Horizontally
1000
1
false
symmetry-vertical
Mirror All Layers &Vertically
Mirror All Layers Vertically
Mirror All Layers Vertically
1000
1
false
&Rotate All Layers...
Rotate All Layers
Rotate All Layers
1000
1
false
object-rotate-right
Rotate All &Layers 90° to the Right
Rotate All Layers 90° to the Right
Rotate All Layers 90° to the Right
1000
1
false
object-rotate-left
Rotate All Layers &90° to the Left
Rotate All Layers 90° to the Left
Rotate All Layers 90° to the Left
1000
1
false
Rotate All Layers &180°
Rotate All Layers 180°
Rotate All Layers 180°
1000
1
false
Scale All &Layers to new Size...
Scale All Layers to new Size
Scale All Layers to new Size
100000
1
false
&Shear All Layers...
Shear All Layers
Shear All Layers
1000
1
false
&Offset Layer...
Offset Layer
Offset Layer
100000
1
false
Clones &Array...
Clones Array
Clones Array
100000
0
false
&Edit metadata...
Edit metadata
Edit metadata
100000
1
false
&Histogram...
Histogram
Histogram
100000
0
false
&Convert Layer Color Space...
Convert Layer Color Space
Convert Layer Color Space
100000
1
false
merge-layer-below
&Merge with Layer Below
Merge with Layer Below
Merge with Layer Below
100000
0
Ctrl+E
false
&Flatten Layer
Flatten Layer
Flatten Layer
100000
0
false
Ras&terize Layer
Rasterize Layer
Rasterize Layer
10000000
1
false
Flatten ima&ge
Flatten image
Flatten image
100000
0
Ctrl+Shift+E
false
La&yer Style...
Layer Style
Layer Style
100000
1
false
Move into previous group
Move into previous group
Move into previous group
0
0
false
Move into next group
Move into next group
Move into next group
0
0
false
Rename current layer
Rename current layer
Rename current layer
100000
0
F2
false
deletelayer
&Remove Layer
Remove Layer
Remove Layer
1000
1
Shift+Delete
false
arrowupblr
Move Layer or Mask Up
Move Layer or Mask Up
Ctrl+PgUp
false
arrowdown
Move Layer or Mask Down
Move Layer or Mask Down
Ctrl+PgDown
false
properties
&Properties...
Properties
Properties
1000
1
F3
false
Set Copy F&rom...
Set the source for the selected clone layer(s).
Set Copy From
1000
1
false
diff --git a/libs/ui/canvas/kis_animation_player.h b/libs/ui/canvas/kis_animation_player.h
index d540dcc697..28996485a9 100644
--- a/libs/ui/canvas/kis_animation_player.h
+++ b/libs/ui/canvas/kis_animation_player.h
@@ -1,88 +1,90 @@
/*
* Copyright (c) 2015 Jouni Pentikäinen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_ANIMATION_PLAYER_H
#define KIS_ANIMATION_PLAYER_H
#include
#include
#include "kritaui_export.h"
class KisCanvas2;
class KRITAUI_EXPORT KisAnimationPlayer : public QObject
{
Q_OBJECT
public:
KisAnimationPlayer(KisCanvas2 *canvas);
~KisAnimationPlayer() override;
void play();
void stop();
void displayFrame(int time);
bool isPlaying();
int currentTime();
qreal playbackSpeed();
void forcedStopOnExit();
qreal effectiveFps() const;
qreal realFps() const;
qreal framesDroppedPortion() const;
+Q_SIGNALS:
+ void sigFrameChanged();
+ void sigPlaybackStarted();
+ void sigPlaybackStopped();
+ void sigPlaybackStatisticsUpdated();
+ void sigFullClipRangeChanged();
+
public Q_SLOTS:
void slotUpdate();
void slotCancelPlayback();
void slotCancelPlaybackSafe();
void slotUpdatePlaybackSpeed(double value);
void slotUpdatePlaybackTimer();
void slotUpdateDropFramesMode();
private Q_SLOTS:
void slotSyncScrubbingAudio(int msecTime);
void slotTryStopScrubbingAudio();
void slotUpdateAudioChunkLength();
void slotAudioChannelChanged();
void slotAudioVolumeChanged();
void slotOnAudioError(const QString &fileName, const QString &message);
-Q_SIGNALS:
- void sigFrameChanged();
- void sigPlaybackStarted();
- void sigPlaybackStopped();
- void sigPlaybackStatisticsUpdated();
- void sigFullClipRangeChanged();
+
private:
void connectCancelSignals();
void disconnectCancelSignals();
void uploadFrame(int time, bool forceSyncAudio);
private:
struct Private;
QScopedPointer m_d;
};
#endif
diff --git a/plugins/dockers/animation/animation_docker.cpp b/plugins/dockers/animation/animation_docker.cpp
index 3fa8f38981..3fbea90660 100644
--- a/plugins/dockers/animation/animation_docker.cpp
+++ b/plugins/dockers/animation/animation_docker.cpp
@@ -1,678 +1,685 @@
/*
* Copyright (c) 2015 Jouni Pentikäinen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "animation_docker.h"
#include "kis_global.h"
#include "kis_canvas2.h"
#include "kis_image.h"
#include
#include
#include
#include "KisViewManager.h"
#include "kis_action_manager.h"
#include "kis_image_animation_interface.h"
#include "kis_animation_player.h"
#include "kis_time_range.h"
#include "kundo2command.h"
#include "kis_post_execution_undo_adapter.h"
#include "kis_keyframe_channel.h"
#include "kis_animation_utils.h"
#include "krita_utils.h"
#include "kis_image_config.h"
#include "kis_config.h"
#include "kis_signals_blocker.h"
#include "kis_node_manager.h"
#include "kis_transform_mask_params_factory_registry.h"
#include "ui_wdg_animation.h"
void setupActionButton(const QString &text,
KisAction::ActivationFlags flags,
bool defaultValue,
QToolButton *button,
KisAction **action)
{
*action = new KisAction(text, button);
(*action)->setActivationFlags(flags);
(*action)->setCheckable(true);
(*action)->setChecked(defaultValue);
button->setDefaultAction(*action);
}
AnimationDocker::AnimationDocker()
: QDockWidget(i18n("Animation"))
, m_canvas(0)
, m_animationWidget(new Ui_WdgAnimation)
, m_mainWindow(0)
{
QWidget* mainWidget = new QWidget(this);
setWidget(mainWidget);
m_animationWidget->setupUi(mainWidget);
}
AnimationDocker::~AnimationDocker()
{
delete m_animationWidget;
}
void AnimationDocker::setCanvas(KoCanvasBase * canvas)
{
if(m_canvas == canvas)
return;
setEnabled(canvas != 0);
if (m_canvas) {
m_canvas->disconnectCanvasObserver(this);
m_canvas->image()->disconnect(this);
m_canvas->image()->animationInterface()->disconnect(this);
m_canvas->animationPlayer()->disconnect(this);
m_canvas->viewManager()->nodeManager()->disconnect(this);
}
m_canvas = dynamic_cast(canvas);
if (m_canvas && m_canvas->image()) {
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
{
KisSignalsBlocker bloker(m_animationWidget->spinFromFrame,
m_animationWidget->spinToFrame,
m_animationWidget->intFramerate);
m_animationWidget->spinFromFrame->setValue(animation->fullClipRange().start());
m_animationWidget->spinToFrame->setValue(animation->fullClipRange().end());
m_animationWidget->intFramerate->setValue(animation->framerate());
}
connect(animation, SIGNAL(sigUiTimeChanged(int)), this, SLOT(slotGlobalTimeChanged()));
connect(animation, SIGNAL(sigFramerateChanged()), this, SLOT(slotFrameRateChanged()));
connect(m_canvas->animationPlayer(), SIGNAL(sigFrameChanged()), this, SLOT(slotGlobalTimeChanged()));
connect(m_canvas->animationPlayer(), SIGNAL(sigPlaybackStopped()), this, SLOT(slotGlobalTimeChanged()));
connect(m_canvas->animationPlayer(), SIGNAL(sigPlaybackStopped()), this, SLOT(updatePlayPauseIcon()));
connect(m_canvas->animationPlayer(), SIGNAL(sigPlaybackStarted()), this, SLOT(updatePlayPauseIcon()));
connect(m_canvas->animationPlayer(), SIGNAL(sigPlaybackStatisticsUpdated()), this, SLOT(updateDropFramesIcon()));
connect(m_animationWidget->doublePlaySpeed,
SIGNAL(valueChanged(double)),
m_canvas->animationPlayer(),
SLOT(slotUpdatePlaybackSpeed(double)));
connect(m_canvas->viewManager()->nodeManager(), SIGNAL(sigNodeActivated(KisNodeSP)),
this, SLOT(slotCurrentNodeChanged(KisNodeSP)));
connect (animation, SIGNAL(sigFullClipRangeChanged()), this, SLOT(updateClipRange()));
slotGlobalTimeChanged();
slotCurrentNodeChanged(m_canvas->viewManager()->nodeManager()->activeNode());
}
slotUpdateIcons();
}
void AnimationDocker::unsetCanvas()
{
setCanvas(0);
}
void AnimationDocker::setViewManager(KisViewManager *view)
{
setActions(view->actionManager());
slotUpdateIcons();
connect(view->mainWindow(), SIGNAL(themeChanged()), this, SLOT(slotUpdateIcons()));
m_mainWindow = view->mainWindow();
}
void AnimationDocker::slotAddOpacityKeyframe()
{
+ // remember current node's opacity and set it once we create a new opacity keyframe
+ KisNodeSP node = m_canvas->viewManager()->activeNode();
+ if (!node) return;
+
addKeyframe(KisKeyframeChannel::Opacity.id(), false);
}
void AnimationDocker::slotDeleteOpacityKeyframe()
{
deleteKeyframe(KisKeyframeChannel::Opacity.id());
}
void AnimationDocker::slotAddTransformKeyframe()
{
if (!m_canvas) return;
KisTransformMask *mask = dynamic_cast(m_canvas->viewManager()->activeNode().data());
if (!mask) return;
const int time = m_canvas->image()->animationInterface()->currentTime();
KUndo2Command *command = new KUndo2Command(kundo2_i18n("Add transform keyframe"));
KisTransformMaskParamsFactoryRegistry::instance()->autoAddKeyframe(mask, time, KisTransformMaskParamsInterfaceSP(), command);
command->redo();
m_canvas->currentImage()->postExecutionUndoAdapter()->addCommand(toQShared(command));
}
void AnimationDocker::slotDeleteTransformKeyframe()
{
deleteKeyframe(KisKeyframeChannel::TransformArguments.id());
}
void AnimationDocker::slotUIRangeChanged()
{
if (!m_canvas || !m_canvas->image()) return;
int fromTime = m_animationWidget->spinFromFrame->value();
int toTime = m_animationWidget->spinToFrame->value();
m_canvas->image()->animationInterface()->setFullClipRange(KisTimeRange::fromTime(fromTime, toTime));
}
void AnimationDocker::slotUIFramerateChanged()
{
if (!m_canvas || !m_canvas->image()) return;
m_canvas->image()->animationInterface()->setFramerate(m_animationWidget->intFramerate->value());
}
void AnimationDocker::slotOnionSkinOptions()
{
if (m_mainWindow) {
QDockWidget *docker = m_mainWindow->dockWidget("OnionSkinsDocker");
if (docker) {
docker->setVisible(!docker->isVisible());
}
}
}
void AnimationDocker::slotGlobalTimeChanged()
{
int time = m_canvas->animationPlayer()->isPlaying() ?
m_canvas->animationPlayer()->currentTime() :
m_canvas->image()->animationInterface()->currentUITime();
m_animationWidget->intCurrentTime->setValue(time);
const int frameRate = m_canvas->image()->animationInterface()->framerate();
const int msec = 1000 * time / frameRate;
QTime realTime;
realTime = realTime.addMSecs(msec);
QString realTimeString = realTime.toString("hh:mm:ss.zzz");
m_animationWidget->intCurrentTime->setToolTip(realTimeString);
}
void AnimationDocker::slotFrameRateChanged()
{
if (!m_canvas || !m_canvas->image()) return;
int fpsOnUI = m_animationWidget->intFramerate->value();
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
if (animation->framerate() != fpsOnUI) {
m_animationWidget->intFramerate->setValue(animation->framerate());
}
}
void AnimationDocker::slotTimeSpinBoxChanged()
{
if (!m_canvas || !m_canvas->image()) return;
int newTime = m_animationWidget->intCurrentTime->value();
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
if (m_canvas->animationPlayer()->isPlaying() ||
newTime == animation->currentUITime()) {
return;
}
animation->requestTimeSwitchWithUndo(newTime);
}
void AnimationDocker::slotPreviousFrame()
{
if (!m_canvas) return;
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
int time = animation->currentUITime() - 1;
if (time >= 0) {
animation->requestTimeSwitchWithUndo(time);
}
}
void AnimationDocker::slotNextFrame()
{
if (!m_canvas) return;
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
int time = animation->currentUITime() + 1;
animation->requestTimeSwitchWithUndo(time);
}
void AnimationDocker::slotPreviousKeyFrame()
{
if (!m_canvas) return;
KisNodeSP node = m_canvas->viewManager()->activeNode();
if (!node) return;
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
int time = animation->currentUITime();
KisKeyframeChannel *content =
node->getKeyframeChannel(KisKeyframeChannel::Content.id());
if (!content) return;
KisKeyframeSP dstKeyframe;
KisKeyframeSP keyframe = content->keyframeAt(time);
if (!keyframe) {
dstKeyframe = content->activeKeyframeAt(time);
} else {
dstKeyframe = content->previousKeyframe(keyframe);
}
if (dstKeyframe) {
animation->requestTimeSwitchWithUndo(dstKeyframe->time());
}
}
void AnimationDocker::slotNextKeyFrame()
{
if (!m_canvas) return;
KisNodeSP node = m_canvas->viewManager()->activeNode();
if (!node) return;
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
int time = animation->currentUITime();
KisKeyframeChannel *content =
node->getKeyframeChannel(KisKeyframeChannel::Content.id());
if (!content) return;
KisKeyframeSP dstKeyframe;
KisKeyframeSP keyframe = content->activeKeyframeAt(time);
if (keyframe) {
dstKeyframe = content->nextKeyframe(keyframe);
}
if (dstKeyframe) {
animation->requestTimeSwitchWithUndo(dstKeyframe->time());
}
}
void AnimationDocker::slotFirstFrame()
{
if (!m_canvas) return;
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
animation->requestTimeSwitchWithUndo(0);
}
void AnimationDocker::slotLastFrame()
{
if (!m_canvas) return;
KisImageAnimationInterface *animation = m_canvas->image()->animationInterface();
animation->requestTimeSwitchWithUndo(animation->totalLength() - 1);
}
void AnimationDocker::slotPlayPause()
{
if (!m_canvas) return;
if (m_canvas->animationPlayer()->isPlaying()) {
m_canvas->animationPlayer()->stop();
} else {
m_canvas->animationPlayer()->play();
}
updatePlayPauseIcon();
}
void AnimationDocker::updatePlayPauseIcon()
{
bool isPlaying = m_canvas && m_canvas->animationPlayer() && m_canvas->animationPlayer()->isPlaying();
m_playPauseAction->setIcon(isPlaying ?
KisIconUtils::loadIcon("animation_stop") :
KisIconUtils::loadIcon("animation_play"));
}
void AnimationDocker::updateLazyFrameIcon()
{
KisImageConfig cfg(true);
const bool value = cfg.lazyFrameCreationEnabled();
m_lazyFrameAction->setIcon(value ?
KisIconUtils::loadIcon("lazyframeOn") :
KisIconUtils::loadIcon("lazyframeOff"));
m_lazyFrameAction->setText(QString("%1 (%2)")
.arg(KisAnimationUtils::lazyFrameCreationActionName)
.arg(KritaUtils::toLocalizedOnOff(value)));
}
void AnimationDocker::updateDropFramesIcon()
{
qreal effectiveFps = 0.0;
qreal realFps = 0.0;
qreal framesDropped = 0.0;
bool isPlaying = false;
KisAnimationPlayer *player =
m_canvas && m_canvas->animationPlayer() ?
m_canvas->animationPlayer() : 0;
if (player) {
effectiveFps = player->effectiveFps();
realFps = player->realFps();
framesDropped = player->framesDroppedPortion();
isPlaying = player->isPlaying();
}
KisConfig cfg(true);
const bool value = cfg.animationDropFrames();
m_dropFramesAction->setIcon(value ?
KisIconUtils::loadIcon(framesDropped > 0.05 ? "droppedframes" : "dropframe") :
KisIconUtils::loadIcon("dropframe"));
QString text;
if (!isPlaying) {
text = QString("%1 (%2)")
.arg(KisAnimationUtils::dropFramesActionName)
.arg(KritaUtils::toLocalizedOnOff(value));
} else {
text = QString("%1 (%2)\n"
"%3\n"
"%4\n"
"%5")
.arg(KisAnimationUtils::dropFramesActionName)
.arg(KritaUtils::toLocalizedOnOff(value))
.arg(i18n("Effective FPS:\t%1", effectiveFps))
.arg(i18n("Real FPS:\t%1", realFps))
.arg(i18n("Frames dropped:\t%1\%", framesDropped * 100));
}
m_dropFramesAction->setText(text);
}
void AnimationDocker::slotUpdateIcons()
{
m_previousFrameAction->setIcon(KisIconUtils::loadIcon("prevframe"));
m_nextFrameAction->setIcon(KisIconUtils::loadIcon("nextframe"));
m_previousKeyFrameAction->setIcon(KisIconUtils::loadIcon("prevkeyframe"));
m_nextKeyFrameAction->setIcon(KisIconUtils::loadIcon("nextkeyframe"));
m_firstFrameAction->setIcon(KisIconUtils::loadIcon("firstframe"));
m_lastFrameAction->setIcon(KisIconUtils::loadIcon("lastframe"));
updatePlayPauseIcon();
updateLazyFrameIcon();
updateDropFramesIcon();
m_animationWidget->btnOnionSkinOptions->setIcon(KisIconUtils::loadIcon("onion_skin_options"));
m_animationWidget->btnOnionSkinOptions->setIconSize(QSize(22, 22));
m_animationWidget->btnNextKeyFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnPreviousKeyFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnFirstFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnLastFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnPreviousFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnPlay->setIconSize(QSize(22, 22));
m_animationWidget->btnNextFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnAddKeyframe->setIconSize(QSize(22, 22));
m_animationWidget->btnAddDuplicateFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnDeleteKeyframe->setIconSize(QSize(22, 22));
m_animationWidget->btnLazyFrame->setIconSize(QSize(22, 22));
m_animationWidget->btnDropFrames->setIconSize(QSize(22, 22));
}
void AnimationDocker::slotLazyFrameChanged(bool value)
{
KisImageConfig cfg(false);
if (value != cfg.lazyFrameCreationEnabled()) {
cfg.setLazyFrameCreationEnabled(value);
updateLazyFrameIcon();
}
}
void AnimationDocker::slotDropFramesChanged(bool value)
{
KisConfig cfg(false);
if (value != cfg.animationDropFrames()) {
cfg.setAnimationDropFrames(value);
updateDropFramesIcon();
}
}
void AnimationDocker::slotCurrentNodeChanged(KisNodeSP node)
{
bool isNodeAnimatable = false;
m_newKeyframeMenu->clear();
m_deleteKeyframeMenu->clear();
if (!node.isNull()) {
if (KisAnimationUtils::supportsContentFrames(node)) {
isNodeAnimatable = true;
KisActionManager::safePopulateMenu(m_newKeyframeMenu, "add_blank_frame", m_actionManager);
KisActionManager::safePopulateMenu(m_deleteKeyframeMenu, "remove_frames", m_actionManager);
}
if (node->inherits("KisLayer")) {
isNodeAnimatable = true;
m_newKeyframeMenu->addAction(m_addOpacityKeyframeAction);
m_deleteKeyframeMenu->addAction(m_deleteOpacityKeyframeAction);
}
/*
if (node->inherits("KisTransformMask")) {
isNodeAnimatable = true;
m_newKeyframeMenu->addAction(m_addTransformKeyframeAction);
m_deleteKeyframeMenu->addAction(m_deleteTransformKeyframeAction);
}
*/
}
m_animationWidget->btnAddKeyframe->setEnabled(isNodeAnimatable);
m_animationWidget->btnAddDuplicateFrame->setEnabled(isNodeAnimatable);
m_animationWidget->btnDeleteKeyframe->setEnabled(isNodeAnimatable);
}
void AnimationDocker::updateClipRange()
{
m_animationWidget->spinFromFrame->setValue(m_canvas->image()->animationInterface()->fullClipRange().start());
m_animationWidget->spinToFrame->setValue(m_canvas->image()->animationInterface()->fullClipRange().end());
}
void AnimationDocker::addKeyframe(const QString &channel, bool copy)
{
if (!m_canvas) return;
KisNodeSP node = m_canvas->viewManager()->activeNode();
if (!node) return;
const int time = m_canvas->image()->animationInterface()->currentTime();
KisAnimationUtils::createKeyframeLazy(m_canvas->image(), node, channel, time, copy);
}
void AnimationDocker::deleteKeyframe(const QString &channel)
{
if (!m_canvas) return;
KisNodeSP node = m_canvas->viewManager()->activeNode();
if (!node) return;
const int time = m_canvas->image()->animationInterface()->currentTime();
KisAnimationUtils::removeKeyframe(m_canvas->image(), node, channel, time);
}
void AnimationDocker::setActions(KisActionManager *actionMan)
{
m_actionManager = actionMan;
if (!m_actionManager) return;
m_previousFrameAction = new KisAction(i18n("Previous Frame"), m_animationWidget->btnPreviousFrame);
m_previousFrameAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnPreviousFrame->setDefaultAction(m_previousFrameAction);
m_nextFrameAction = new KisAction(i18n("Next Frame"), m_animationWidget->btnNextFrame);
m_nextFrameAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnNextFrame->setDefaultAction(m_nextFrameAction);
m_previousKeyFrameAction = new KisAction(i18n("Previous Key Frame"), m_animationWidget->btnPreviousKeyFrame);
m_previousKeyFrameAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnPreviousKeyFrame->setDefaultAction(m_previousKeyFrameAction);
m_nextKeyFrameAction = new KisAction(i18n("Next Key Frame"), m_animationWidget->btnNextKeyFrame);
m_nextKeyFrameAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnNextKeyFrame->setDefaultAction(m_nextKeyFrameAction);
m_firstFrameAction = new KisAction(i18n("First Frame"), m_animationWidget->btnFirstFrame);
m_firstFrameAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnFirstFrame->setDefaultAction(m_firstFrameAction);
m_lastFrameAction = new KisAction(i18n("Last Frame"), m_animationWidget->btnLastFrame);
m_lastFrameAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnLastFrame->setDefaultAction(m_lastFrameAction);
m_playPauseAction = new KisAction(i18n("Play / Stop"), m_animationWidget->btnPlay);
m_playPauseAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnPlay->setDefaultAction(m_playPauseAction);
KisAction *action = 0;
action = m_actionManager->createAction("add_blank_frame");
m_animationWidget->btnAddKeyframe->setDefaultAction(action);
action = m_actionManager->createAction("add_duplicate_frame");
m_animationWidget->btnAddDuplicateFrame->setDefaultAction(action);
action = m_actionManager->createAction("remove_frames");
m_animationWidget->btnDeleteKeyframe->setDefaultAction(action);
m_newKeyframeMenu = new QMenu(this);
m_animationWidget->btnAddKeyframe->setMenu(m_newKeyframeMenu);
m_animationWidget->btnAddKeyframe->setPopupMode(QToolButton::MenuButtonPopup);
m_deleteKeyframeMenu = new QMenu(this);
m_animationWidget->btnDeleteKeyframe->setMenu(m_deleteKeyframeMenu);
m_animationWidget->btnDeleteKeyframe->setPopupMode(QToolButton::MenuButtonPopup);
- m_addOpacityKeyframeAction = new KisAction(KisAnimationUtils::addOpacityKeyframeActionName);
- m_deleteOpacityKeyframeAction = new KisAction(KisAnimationUtils::removeOpacityKeyframeActionName);
+
+ m_addOpacityKeyframeAction = m_actionManager->createAction("insert_opacity_keyframe");
+ m_deleteOpacityKeyframeAction = m_actionManager->createAction("remove_opacity_keyframe");
+
+
m_addTransformKeyframeAction = new KisAction(KisAnimationUtils::addTransformKeyframeActionName);
m_deleteTransformKeyframeAction = new KisAction(KisAnimationUtils::removeTransformKeyframeActionName);
// other new stuff
m_actionManager->addAction("previous_frame", m_previousFrameAction);
m_actionManager->addAction("next_frame", m_nextFrameAction);
m_actionManager->addAction("previous_keyframe", m_previousKeyFrameAction);
m_actionManager->addAction("next_keyframe", m_nextKeyFrameAction);
m_actionManager->addAction("first_frame", m_firstFrameAction);
m_actionManager->addAction("last_frame", m_lastFrameAction);
{
KisImageConfig cfg(true);
setupActionButton(KisAnimationUtils::lazyFrameCreationActionName,
KisAction::ACTIVE_IMAGE,
cfg.lazyFrameCreationEnabled(),
m_animationWidget->btnLazyFrame,
&m_lazyFrameAction);
}
{
KisConfig cfg(true);
setupActionButton(KisAnimationUtils::dropFramesActionName,
KisAction::ACTIVE_IMAGE,
cfg.animationDropFrames(),
m_animationWidget->btnDropFrames,
&m_dropFramesAction);
}
// these actions are created in the setupActionButton() above, so we need to add actions after that
m_actionManager->addAction("lazy_frame", m_lazyFrameAction);
m_actionManager->addAction("drop_frames", m_dropFramesAction);
m_actionManager->addAction("toggle_playback", m_playPauseAction);
QFont font;
font.setPointSize(1.7 * font.pointSize());
font.setBold(true);
m_animationWidget->intCurrentTime->setFont(font);
connect(m_previousFrameAction, SIGNAL(triggered()), this, SLOT(slotPreviousFrame()));
connect(m_nextFrameAction, SIGNAL(triggered()), this, SLOT(slotNextFrame()));
connect(m_previousKeyFrameAction, SIGNAL(triggered()), this, SLOT(slotPreviousKeyFrame()));
connect(m_nextKeyFrameAction, SIGNAL(triggered()), this, SLOT(slotNextKeyFrame()));
connect(m_firstFrameAction, SIGNAL(triggered()), this, SLOT(slotFirstFrame()));
connect(m_lastFrameAction, SIGNAL(triggered()), this, SLOT(slotLastFrame()));
connect(m_playPauseAction, SIGNAL(triggered()), this, SLOT(slotPlayPause()));
connect(m_lazyFrameAction, SIGNAL(toggled(bool)), this, SLOT(slotLazyFrameChanged(bool)));
connect(m_dropFramesAction, SIGNAL(toggled(bool)), this, SLOT(slotDropFramesChanged(bool)));
connect(m_addOpacityKeyframeAction, SIGNAL(triggered(bool)), this, SLOT(slotAddOpacityKeyframe()));
connect(m_deleteOpacityKeyframeAction, SIGNAL(triggered(bool)), this, SLOT(slotDeleteOpacityKeyframe()));
connect(m_addTransformKeyframeAction, SIGNAL(triggered(bool)), this, SLOT(slotAddTransformKeyframe()));
connect(m_deleteTransformKeyframeAction, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTransformKeyframe()));
m_animationWidget->btnOnionSkinOptions->setToolTip(i18n("Onion Skins"));
connect(m_animationWidget->btnOnionSkinOptions, SIGNAL(clicked()), this, SLOT(slotOnionSkinOptions()));
connect(m_animationWidget->spinFromFrame, SIGNAL(valueChanged(int)), this, SLOT(slotUIRangeChanged()));
connect(m_animationWidget->spinToFrame, SIGNAL(valueChanged(int)), this, SLOT(slotUIRangeChanged()));
connect(m_animationWidget->intFramerate, SIGNAL(valueChanged(int)), this, SLOT(slotUIFramerateChanged()));
connect(m_animationWidget->intCurrentTime, SIGNAL(valueChanged(int)), SLOT(slotTimeSpinBoxChanged()));
}
diff --git a/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.cpp b/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.cpp
index cad623b6f4..2c5143085c 100644
--- a/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.cpp
+++ b/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.cpp
@@ -1,209 +1,225 @@
/*
* Copyright (c) 2016 Jouni Pentikäinen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_animation_curves_keyframe_delegate.h"
#include
#include
#include
#include "kis_animation_curves_model.h"
#include "kis_keyframe.h"
-const int NODE_RENDER_RADIUS = 2;
+const int NODE_RENDER_RADIUS = 4;
const int NODE_UI_RADIUS = 8;
struct KisAnimationCurvesKeyframeDelegate::Private
{
Private(const TimelineRulerHeader *horizontalRuler, const KisAnimationCurvesValueRuler *verticalRuler)
: horizontalRuler(horizontalRuler)
, verticalRuler(verticalRuler)
{}
const TimelineRulerHeader *horizontalRuler;
const KisAnimationCurvesValueRuler *verticalRuler;
QPointF selectionOffset;
int adjustedHandle;
QPointF handleAdjustment;
+
};
KisAnimationCurvesKeyframeDelegate::KisAnimationCurvesKeyframeDelegate(const TimelineRulerHeader *horizontalRuler, const KisAnimationCurvesValueRuler *verticalRuler, QObject *parent)
: QAbstractItemDelegate(parent)
, m_d(new Private(horizontalRuler, verticalRuler))
-{}
+{
+}
KisAnimationCurvesKeyframeDelegate::~KisAnimationCurvesKeyframeDelegate()
{}
+
void KisAnimationCurvesKeyframeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
bool selected = option.state & QStyle::State_Selected;
bool active = option.state & QStyle::State_HasFocus;
QPointF center = nodeCenter(index, selected);
QColor color;
QColor bgColor = qApp->palette().color(QPalette::Window);
if (selected) {
color = (bgColor.value() > 128) ? Qt::black : Qt::white;
} else {
color = index.data(KisAnimationCurvesModel::CurveColorRole).value();
}
painter->setPen(QPen(color, 0));
painter->setBrush(color);
painter->drawEllipse(center, NODE_RENDER_RADIUS, NODE_RENDER_RADIUS);
if (selected) {
painter->setPen(QPen(color, 1));
painter->setBrush(bgColor);
if (hasHandle(index, 0)) {
QPointF leftTangent = leftHandle(index, active);
paintHandle(painter, center, leftTangent);
}
if (hasHandle(index, 1)) {
QPointF rightTangent = rightHandle(index, active);
paintHandle(painter, center, rightTangent);
}
}
}
QSize KisAnimationCurvesKeyframeDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
return QSize(2*NODE_UI_RADIUS, 2*NODE_UI_RADIUS);
}
QPointF KisAnimationCurvesKeyframeDelegate::nodeCenter(const QModelIndex index, bool selected) const
{
int section = m_d->horizontalRuler->logicalIndex(index.column());
int x = m_d->horizontalRuler->sectionViewportPosition(section)
+ (m_d->horizontalRuler->sectionSize(section) / 2);
float value = index.data(KisAnimationCurvesModel::ScalarValueRole).toReal();
float y = m_d->verticalRuler->mapValueToView(value);
QPointF center = QPointF(x, y);
if (selected) center += m_d->selectionOffset;
return center;
}
bool KisAnimationCurvesKeyframeDelegate::hasHandle(const QModelIndex index, int handle) const
{
QModelIndex interpolatedIndex;
if (handle == 0) {
// Left handle: use previous keyframe's interpolation mode
QVariant previous = index.data(KisAnimationCurvesModel::PreviousKeyframeTime);
if (!previous.isValid()) return false;
interpolatedIndex = index.model()->index(index.row(), previous.toInt());
} else {
interpolatedIndex = index;
}
return (interpolatedIndex.data(KisAnimationCurvesModel::InterpolationModeRole).toInt() == KisKeyframe::Bezier);
}
QPointF KisAnimationCurvesKeyframeDelegate::leftHandle(const QModelIndex index, bool active) const
{
return handlePosition(index, active, 0);
}
QPointF KisAnimationCurvesKeyframeDelegate::rightHandle(const QModelIndex index, bool active) const
{
return handlePosition(index, active, 1);
}
QPointF KisAnimationCurvesKeyframeDelegate::handlePosition(const QModelIndex index, bool active, int handle) const
{
int role = (handle == 0) ? KisAnimationCurvesModel::LeftTangentRole : KisAnimationCurvesModel::RightTangentRole;
QPointF tangent = index.data(role).toPointF();
float x = tangent.x() * m_d->horizontalRuler->defaultSectionSize();
float y = tangent.y() * m_d->verticalRuler->scaleFactor();
QPointF handlePos = QPointF(x, y);
if (active && !m_d->handleAdjustment.isNull()) {
if (handle == m_d->adjustedHandle) {
handlePos += m_d->handleAdjustment;
if ((handle == 0 && handlePos.x() > 0) ||
(handle == 1 && handlePos.x() < 0)) {
handlePos.setX(0);
}
} else if (index.data(KisAnimationCurvesModel::TangentsModeRole).toInt() == KisKeyframe::Smooth) {
qreal length = QVector2D(handlePos).length();
QVector2D opposite(handlePosition(index, active, 1-handle));
handlePos = (-length * opposite.normalized()).toPointF();
}
}
return handlePos;
}
void KisAnimationCurvesKeyframeDelegate::setSelectedItemVisualOffset(QPointF offset)
{
m_d->selectionOffset = offset;
}
void KisAnimationCurvesKeyframeDelegate::setHandleAdjustment(QPointF offset, int handle)
{
m_d->adjustedHandle = handle;
m_d->handleAdjustment = offset;
}
QPointF KisAnimationCurvesKeyframeDelegate::unscaledTangent(QPointF handlePosition) const
{
qreal x = handlePosition.x() / m_d->horizontalRuler->defaultSectionSize();
qreal y = handlePosition.y() / m_d->verticalRuler->scaleFactor();
return QPointF(x, y);
}
void KisAnimationCurvesKeyframeDelegate::paintHandle(QPainter *painter, QPointF nodePos, QPointF tangent) const
{
QPointF handlePos = nodePos + tangent;
painter->drawLine(nodePos, handlePos);
painter->drawEllipse(handlePos, NODE_RENDER_RADIUS, NODE_RENDER_RADIUS);
}
QRect KisAnimationCurvesKeyframeDelegate::itemRect(const QModelIndex index) const
{
QPointF center = nodeCenter(index, false);
return QRect(center.x() - NODE_UI_RADIUS, center.y() - NODE_UI_RADIUS, 2*NODE_UI_RADIUS, 2*NODE_UI_RADIUS);
}
+QRect KisAnimationCurvesKeyframeDelegate::frameRect(const QModelIndex index) const
+{
+ int section = m_d->horizontalRuler->logicalIndex(index.column());
+ int x = m_d->horizontalRuler->sectionViewportPosition(section);
+ int xSize = m_d->horizontalRuler->sectionSize(section);
+
+ float value = index.data(KisAnimationCurvesModel::ScalarValueRole).toReal();
+ float y = m_d->verticalRuler->mapValueToView(value);
+ int ySize = m_d->verticalRuler->height();
+
+ return QRect(x, y, xSize, ySize);
+}
+
QRect KisAnimationCurvesKeyframeDelegate::visualRect(const QModelIndex index) const
{
QPointF center = nodeCenter(index, false);
QPointF leftHandlePos = center + leftHandle(index, false);
QPointF rightHandlePos = center + rightHandle(index, false);
int minX = qMin(center.x(), leftHandlePos.x()) - NODE_RENDER_RADIUS;
int maxX = qMax(center.x(), rightHandlePos.x()) + NODE_RENDER_RADIUS;
int minY = qMin(center.y(), qMin(leftHandlePos.y(), rightHandlePos.y())) - NODE_RENDER_RADIUS;
int maxY = qMax(center.y(), qMax(leftHandlePos.y(), rightHandlePos.y())) + NODE_RENDER_RADIUS;
return QRect(QPoint(minX, minY), QPoint(maxX, maxY));
}
diff --git a/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.h b/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.h
index 2182b480fa..c1e7a8078a 100644
--- a/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.h
+++ b/plugins/dockers/animation/kis_animation_curves_keyframe_delegate.h
@@ -1,59 +1,61 @@
/*
* Copyright (c) 2016 Jouni Pentikäinen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_ANIMATION_CURVES_KEYFRAME_DELEGATE_H
#define _KIS_ANIMATION_CURVES_KEYFRAME_DELEGATE_H
#include
#include "timeline_ruler_header.h"
#include "kis_animation_curves_value_ruler.h"
class KisAnimationCurvesKeyframeDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
KisAnimationCurvesKeyframeDelegate(const TimelineRulerHeader *horizontalRuler, const KisAnimationCurvesValueRuler *verticalRuler, QObject *parent);
~KisAnimationCurvesKeyframeDelegate() override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QPointF nodeCenter(const QModelIndex index, bool selected) const;
bool hasHandle(const QModelIndex index, int handle) const;
QPointF leftHandle(const QModelIndex index, bool active) const;
QPointF rightHandle(const QModelIndex index, bool active) const;
void setSelectedItemVisualOffset(QPointF offset);
void setHandleAdjustment(QPointF offset, int handle);
QPointF unscaledTangent(QPointF handlePosition) const;
QRect itemRect(const QModelIndex index) const;
+ QRect frameRect(const QModelIndex index) const;
QRect visualRect(const QModelIndex index) const;
private:
struct Private;
const QScopedPointer m_d;
void paintHandle(QPainter *painter, QPointF nodePos, QPointF tangent) const;
QPointF handlePosition(const QModelIndex index, bool active, int handle) const;
+
};
#endif
diff --git a/plugins/dockers/animation/kis_animation_curves_view.cpp b/plugins/dockers/animation/kis_animation_curves_view.cpp
index b06308cc01..7c390213a7 100644
--- a/plugins/dockers/animation/kis_animation_curves_view.cpp
+++ b/plugins/dockers/animation/kis_animation_curves_view.cpp
@@ -1,742 +1,796 @@
/*
* Copyright (c) 2016 Jouni Pentikäinen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_animation_curves_view.h"
#include
#include
#include
#include
#include
#include
#include "kis_animation_curves_model.h"
#include "timeline_ruler_header.h"
#include "kis_animation_curves_value_ruler.h"
#include "kis_animation_curves_keyframe_delegate.h"
#include "kis_scalar_keyframe_channel.h"
#include "kis_zoom_button.h"
#include "kis_custom_modifiers_catcher.h"
+#include "krita_utils.h"
+
const int VERTICAL_PADDING = 30;
struct KisAnimationCurvesView::Private
{
Private()
: model(0)
, isDraggingKeyframe(false)
, isAdjustingHandle(false)
, panning(false)
{}
KisAnimationCurvesModel *model;
TimelineRulerHeader *horizontalHeader;
KisAnimationCurvesValueRuler *verticalHeader;
KisAnimationCurvesKeyframeDelegate *itemDelegate;
KisZoomButton *horizontalZoomButton;
KisZoomButton *verticalZoomButton;
KisCustomModifiersCatcher *modifiersCatcher;
bool isDraggingKeyframe;
bool isAdjustingHandle;
int adjustedHandle; // 0 = left, 1 = right
QPoint dragStart;
QPoint dragOffset;
int horizontalZoomStillPointIndex;
int horizontalZoomStillPointOriginalOffset;
qreal verticalZoomStillPoint;
qreal verticalZoomStillPointOriginalOffset;
bool panning;
QPoint panStartOffset;
};
KisAnimationCurvesView::KisAnimationCurvesView(QWidget *parent)
: QAbstractItemView(parent)
, m_d(new Private())
{
m_d->horizontalHeader = new TimelineRulerHeader(this);
+
m_d->verticalHeader = new KisAnimationCurvesValueRuler(this);
m_d->itemDelegate = new KisAnimationCurvesKeyframeDelegate(m_d->horizontalHeader, m_d->verticalHeader, this);
m_d->modifiersCatcher = new KisCustomModifiersCatcher(this);
m_d->modifiersCatcher->addModifier("pan-zoom", Qt::Key_Space);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this);
if (scroller){
connect(scroller, SIGNAL(stateChanged(QScroller::State)),
this, SLOT(slotScrollerStateChanged(QScroller::State)));
}
+
}
KisAnimationCurvesView::~KisAnimationCurvesView()
{}
void KisAnimationCurvesView::setModel(QAbstractItemModel *model)
{
m_d->model = dynamic_cast(model);
QAbstractItemView::setModel(model);
m_d->horizontalHeader->setModel(model);
connect(model, &QAbstractItemModel::rowsInserted,
this, &KisAnimationCurvesView::slotRowsChanged);
connect(model, &QAbstractItemModel::rowsRemoved,
this, &KisAnimationCurvesView::slotRowsChanged);
connect(model, &QAbstractItemModel::dataChanged,
this, &KisAnimationCurvesView::slotDataChanged);
connect(model, &QAbstractItemModel::headerDataChanged,
this, &KisAnimationCurvesView::slotHeaderDataChanged);
+
}
void KisAnimationCurvesView::setZoomButtons(KisZoomButton *horizontal, KisZoomButton *vertical)
{
m_d->horizontalZoomButton = horizontal;
m_d->verticalZoomButton = vertical;
connect(horizontal, &KisZoomButton::zoomStarted, this, &KisAnimationCurvesView::slotHorizontalZoomStarted);
connect(horizontal, &KisZoomButton::zoomLevelChanged, this, &KisAnimationCurvesView::slotHorizontalZoomLevelChanged);
connect(vertical, &KisZoomButton::zoomStarted, this, &KisAnimationCurvesView::slotVerticalZoomStarted);
connect(vertical, &KisZoomButton::zoomLevelChanged, this, &KisAnimationCurvesView::slotVerticalZoomLevelChanged);
}
QRect KisAnimationCurvesView::visualRect(const QModelIndex &index) const
{
return m_d->itemDelegate->itemRect(index);
}
void KisAnimationCurvesView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint)
{
// TODO
Q_UNUSED(index);
Q_UNUSED(hint);
}
QModelIndex KisAnimationCurvesView::indexAt(const QPoint &point) const
{
if (!model()) return QModelIndex();
int time = m_d->horizontalHeader->logicalIndexAt(point.x());
int rows = model()->rowCount();
for (int row=0; row < rows; row++) {
QModelIndex index = model()->index(row, time);
if (index.data(KisTimeBasedItemModel::SpecialKeyframeExists).toBool()) {
QRect nodePos = m_d->itemDelegate->itemRect(index);
if (nodePos.contains(point)) {
return index;
}
}
}
return QModelIndex();
}
void KisAnimationCurvesView::paintEvent(QPaintEvent *e)
{
QPainter painter(viewport());
QRect r = e->rect();
r.translate(dirtyRegionOffset());
int firstFrame = m_d->horizontalHeader->logicalIndexAt(r.left());
int lastFrame = m_d->horizontalHeader->logicalIndexAt(r.right());
if (lastFrame == -1) lastFrame = model()->columnCount();
+
+ paintFrames(painter);
+
paintCurves(painter, firstFrame, lastFrame);
paintKeyframes(painter, firstFrame, lastFrame);
}
+void KisAnimationCurvesView::paintFrames(QPainter &painter)
+{
+ const QColor textColor = qApp->palette().text().color();
+ const QColor backgroundColor = qApp->palette().background().color();
+
+
+ // paint vertical lines so it is easier to tell where each frame starts/stops
+ QColor blendedColor = KritaUtils::blendColors(textColor, backgroundColor, 0.2);
+ painter.setPen(QPen(blendedColor, 1));
+ int channels = model()->rowCount();
+ for (int channel = 0; channel < channels; channel++) {
+
+ // draw border around entire frame, so override the height and Y position
+ for (int time = 0; time <= model()->columnCount(); time++) {
+
+ QModelIndex index = model()->index(channel, time);
+ QRect frameRect = m_d->itemDelegate->frameRect(index);
+
+ int offset = 0;
+ if (m_d->horizontalHeader && m_d->horizontalHeader->offset()) {
+ offset = m_d->horizontalHeader->offset();
+ }
+
+ int horizontalStepSize = m_d->horizontalHeader->defaultSectionSize();
+ int viewportHeight = 9999;// makes sure the vertical lines hit the bottom
+
+ frameRect.setX( (horizontalStepSize * time) - offset );
+ frameRect.setHeight(viewportHeight);
+ frameRect.setY(-10); // hides the top border
+
+ painter.drawLine(frameRect.topRight(), frameRect.bottomRight());
+ }
+
+ }
+}
+
void KisAnimationCurvesView::paintCurves(QPainter &painter, int firstFrame, int lastFrame)
{
int channels = model()->rowCount();
for (int channel = 0; channel < channels; channel++) {
QModelIndex index0 = model()->index(channel, 0);
if (!isIndexHidden(index0)) {
QColor color = index0.data(KisAnimationCurvesModel::CurveColorRole).value();
painter.setPen(QPen(color, 1));
paintCurve(channel, firstFrame, lastFrame, painter);
}
}
}
void KisAnimationCurvesView::paintCurve(int channel, int firstFrame, int lastFrame, QPainter &painter)
{
int selectionOffset = m_d->isDraggingKeyframe ? (m_d->dragOffset.x() / m_d->horizontalHeader->defaultSectionSize()) : 0;
QModelIndex index = findNextKeyframeIndex(channel, firstFrame+1, selectionOffset, true);
if (!index.isValid()) {
index = findNextKeyframeIndex(channel, firstFrame, selectionOffset, false);
}
if (!index.isValid()) return;
QPointF previousKeyPos = m_d->itemDelegate->nodeCenter(index, selectionModel()->isSelected(index));
QPointF rightTangent = m_d->itemDelegate->rightHandle(index, index == currentIndex());
while(index.column() <= lastFrame) {
int interpolationMode = index.data(KisAnimationCurvesModel::InterpolationModeRole).toInt();
int time = (m_d->isDraggingKeyframe && selectionModel()->isSelected(index)) ? index.column() + selectionOffset : index.column();
index = findNextKeyframeIndex(channel, time, selectionOffset, false);
if (!index.isValid()) return;
bool active = (index == currentIndex());
QPointF nextKeyPos = m_d->itemDelegate->nodeCenter(index, selectionModel()->isSelected(index));
QPointF leftTangent = m_d->itemDelegate->leftHandle(index, active);
if (interpolationMode == KisKeyframe::Constant) {
painter.drawLine(previousKeyPos, QPointF(nextKeyPos.x(), previousKeyPos.y()));
} else if (interpolationMode == KisKeyframe::Linear) {
painter.drawLine(previousKeyPos, nextKeyPos);
} else {
paintCurveSegment(painter, previousKeyPos, rightTangent, leftTangent, nextKeyPos);
}
previousKeyPos = nextKeyPos;
rightTangent = m_d->itemDelegate->rightHandle(index, active);
}
}
void KisAnimationCurvesView::paintCurveSegment(QPainter &painter, QPointF pos1, QPointF rightTangent, QPointF leftTangent, QPointF pos2) {
const int steps = 16;
QPointF previousPos;
for (int step = 0; step <= steps; step++) {
qreal t = 1.0 * step / steps;
QPointF nextPos = KisScalarKeyframeChannel::interpolate(pos1, rightTangent, leftTangent, pos2, t);
if (step > 0) {
painter.drawLine(previousPos, nextPos);
}
previousPos = nextPos;
}
}
void KisAnimationCurvesView::paintKeyframes(QPainter &painter, int firstFrame, int lastFrame)
{
int channels = model()->rowCount();
for (int channel = 0; channel < channels; channel++) {
for (int time=firstFrame; time <= lastFrame; time++) {
QModelIndex index = model()->index(channel, time);
bool keyframeExists = model()->data(index, KisAnimationCurvesModel::SpecialKeyframeExists).toReal();
if (keyframeExists && !isIndexHidden(index)) {
QStyleOptionViewItem opt;
if (selectionModel()->isSelected(index)) {
opt.state |= QStyle::State_Selected;
}
if (index == selectionModel()->currentIndex()) {
opt.state |= QStyle::State_HasFocus;
}
m_d->itemDelegate->paint(&painter, opt, index);
}
}
}
}
QModelIndex KisAnimationCurvesView::findNextKeyframeIndex(int channel, int time, int selectionOffset, bool backward)
{
KisAnimationCurvesModel::ItemDataRole role =
backward ? KisAnimationCurvesModel::PreviousKeyframeTime : KisAnimationCurvesModel::NextKeyframeTime;
QModelIndex currentIndex = model()->index(channel, time);
if (!selectionOffset) {
QVariant next = currentIndex.data(role);
return (next.isValid()) ? model()->index(channel, next.toInt()) : QModelIndex();
} else {
// Find the next unselected index
QModelIndex nextIndex = currentIndex;
do {
QVariant next = nextIndex.data(role);
nextIndex = (next.isValid()) ? model()->index(channel, next.toInt()) : QModelIndex();
} while(nextIndex.isValid() && selectionModel()->isSelected(nextIndex));
// Find the next selected index, accounting for D&D offset
QModelIndex draggedIndex = model()->index(channel, qMax(0, time - selectionOffset));
do {
QVariant next = draggedIndex.data(role);
draggedIndex = (next.isValid()) ? model()->index(channel, next.toInt()) : QModelIndex();
} while(draggedIndex.isValid() && !selectionModel()->isSelected(draggedIndex));
// Choose the earlier of the two
if (draggedIndex.isValid() && nextIndex.isValid()) {
if (draggedIndex.column() + selectionOffset <= nextIndex.column()) {
return draggedIndex;
} else {
return nextIndex;
}
} else if (draggedIndex.isValid()) {
return draggedIndex;
} else {
return nextIndex;
}
}
}
void KisAnimationCurvesView::findExtremes(qreal *minimum, qreal *maximum)
{
if (!model()) return;
qreal min = qInf();
qreal max = -qInf();
int rows = model()->rowCount();
for (int row = 0; row < rows; row++) {
QModelIndex index = model()->index(row, 0);
if (isIndexHidden(index)) continue;
QVariant nextTime;
do {
qreal value = index.data(KisAnimationCurvesModel::ScalarValueRole).toReal();
if (value < min) min = value;
if (value > max) max = value;
nextTime = index.data(KisAnimationCurvesModel::NextKeyframeTime);
if (nextTime.isValid()) index = model()->index(row, nextTime.toInt());
} while (nextTime.isValid());
}
if (qIsFinite(min)) *minimum = min;
if (qIsFinite(max)) *maximum = max;
}
void KisAnimationCurvesView::updateVerticalRange()
{
if (!model()) return;
qreal minimum = 0;
qreal maximum = 0;
findExtremes(&minimum, &maximum);
int viewMin = maximum * m_d->verticalHeader->scaleFactor();
int viewMax = minimum * m_d->verticalHeader->scaleFactor();
viewMin -= VERTICAL_PADDING;
viewMax += VERTICAL_PADDING;
verticalScrollBar()->setRange(viewMin, viewMax - viewport()->height());
}
void KisAnimationCurvesView::startPan(QPoint mousePos)
{
m_d->dragStart = mousePos;
m_d->panStartOffset = QPoint(horizontalOffset(), verticalOffset());
m_d->panning = true;
}
QModelIndex KisAnimationCurvesView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
// TODO
Q_UNUSED(cursorAction);
Q_UNUSED(modifiers);
return QModelIndex();
}
int KisAnimationCurvesView::horizontalOffset() const
{
return m_d->horizontalHeader->offset();
}
int KisAnimationCurvesView::verticalOffset() const
{
return m_d->verticalHeader->offset();
}
bool KisAnimationCurvesView::isIndexHidden(const QModelIndex &index) const
{
return !index.data(KisAnimationCurvesModel::CurveVisibleRole).toBool();
}
void KisAnimationCurvesView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
{
int timeFrom = m_d->horizontalHeader->logicalIndexAt(rect.left());
int timeTo = m_d->horizontalHeader->logicalIndexAt(rect.right());
QItemSelection selection;
int rows = model()->rowCount();
for (int row=0; row < rows; row++) {
for (int time = timeFrom; time <= timeTo; time++) {
QModelIndex index = model()->index(row, time);
if (index.data(KisTimeBasedItemModel::SpecialKeyframeExists).toBool()) {
QRect itemRect = m_d->itemDelegate->itemRect(index);
if (itemRect.intersects(rect)) {
selection.select(index, index);
}
}
}
}
selectionModel()->select(selection, command);
}
QRegion KisAnimationCurvesView::visualRegionForSelection(const QItemSelection &selection) const
{
QRegion region;
Q_FOREACH(QModelIndex index, selection.indexes()) {
region += m_d->itemDelegate->visualRect(index);
}
return region;
}
void KisAnimationCurvesView::mousePressEvent(QMouseEvent *e)
{
if (m_d->modifiersCatcher->modifierPressed("pan-zoom")) {
if (e->button() == Qt::LeftButton) {
startPan(e->pos());
} else {
qreal horizontalStaticPoint = m_d->horizontalHeader->logicalIndexAt(e->pos().x());
qreal verticalStaticPoint = m_d->verticalHeader->mapViewToValue(e->pos().y());
m_d->horizontalZoomButton->beginZoom(QPoint(e->pos().x(), 0), horizontalStaticPoint);
m_d->verticalZoomButton->beginZoom(QPoint(0, e->pos().y()), verticalStaticPoint);
}
} else if (e->button() == Qt::LeftButton) {
m_d->dragStart = e->pos();
Q_FOREACH(QModelIndex index, selectedIndexes()) {
QPointF center = m_d->itemDelegate->nodeCenter(index, false);
bool hasLeftHandle = m_d->itemDelegate->hasHandle(index, 0);
bool hasRightHandle = m_d->itemDelegate->hasHandle(index, 1);
QPointF leftHandle = center + m_d->itemDelegate->leftHandle(index, false);
QPointF rightHandle = center + m_d->itemDelegate->rightHandle(index, false);
if (hasLeftHandle && (e->localPos() - leftHandle).manhattanLength() < 8) {
m_d->isAdjustingHandle = true;
m_d->adjustedHandle = 0;
setCurrentIndex(index);
return;
} else if (hasRightHandle && (e->localPos() - rightHandle).manhattanLength() < 8) {
m_d->isAdjustingHandle = true;
m_d->adjustedHandle = 1;
setCurrentIndex(index);
return;
}
}
}
QAbstractItemView::mousePressEvent(e);
}
void KisAnimationCurvesView::mouseMoveEvent(QMouseEvent *e)
{
if (m_d->modifiersCatcher->modifierPressed("pan-zoom")) {
if (e->buttons() & Qt::LeftButton) {
if (!m_d->panning) startPan(e->pos());
QPoint diff = e->pos() - m_d->dragStart;
QPoint newOffset = m_d->panStartOffset - diff;
horizontalScrollBar()->setValue(newOffset.x());
verticalScrollBar()->setValue(newOffset.y());
m_d->verticalHeader->setOffset(newOffset.y());
viewport()->update();
} else {
m_d->horizontalZoomButton->continueZoom(QPoint(e->pos().x(), 0));
m_d->verticalZoomButton->continueZoom(QPoint(0, e->pos().y()));
}
} else if (e->buttons() & Qt::LeftButton) {
+
m_d->dragOffset = e->pos() - m_d->dragStart;
if (m_d->isAdjustingHandle) {
m_d->itemDelegate->setHandleAdjustment(m_d->dragOffset, m_d->adjustedHandle);
viewport()->update();
return;
} else if (m_d->isDraggingKeyframe) {
m_d->itemDelegate->setSelectedItemVisualOffset(m_d->dragOffset);
viewport()->update();
return;
} else if (selectionModel()->hasSelection()) {
if ((e->pos() - m_d->dragStart).manhattanLength() > QApplication::startDragDistance()) {
m_d->isDraggingKeyframe = true;
}
}
}
QAbstractItemView::mouseMoveEvent(e);
}
void KisAnimationCurvesView::mouseReleaseEvent(QMouseEvent *e)
{
+
if (e->button() == Qt::LeftButton) {
m_d->panning = false;
if (m_d->isDraggingKeyframe) {
QModelIndexList indexes = selectedIndexes();
int timeOffset = m_d->dragOffset.x() / m_d->horizontalHeader->defaultSectionSize();
qreal valueOffset = m_d->dragOffset.y() / m_d->verticalHeader->scaleFactor();
KisAnimationCurvesModel *curvesModel = dynamic_cast(model());
curvesModel->adjustKeyframes(indexes, timeOffset, valueOffset);
m_d->isDraggingKeyframe = false;
m_d->itemDelegate->setSelectedItemVisualOffset(QPointF());
viewport()->update();
} else if (m_d->isAdjustingHandle) {
QModelIndex index = currentIndex();
int mode = index.data(KisAnimationCurvesModel::TangentsModeRole).toInt();
m_d->model->beginCommand(kundo2_i18n("Adjust tangent"));
if (mode == KisKeyframe::Smooth) {
QPointF leftHandle = m_d->itemDelegate->leftHandle(index, true);
QPointF rightHandle = m_d->itemDelegate->rightHandle(index, true);
QPointF leftTangent = m_d->itemDelegate->unscaledTangent(leftHandle);
QPointF rightTangent = m_d->itemDelegate->unscaledTangent(rightHandle);
model()->setData(index, leftTangent, KisAnimationCurvesModel::LeftTangentRole);
model()->setData(index, rightTangent, KisAnimationCurvesModel::RightTangentRole);
} else {
if (m_d->adjustedHandle == 0) {
QPointF leftHandle = m_d->itemDelegate->leftHandle(index, true);
model()->setData(index, m_d->itemDelegate->unscaledTangent(leftHandle), KisAnimationCurvesModel::LeftTangentRole);
} else {
QPointF rightHandle = m_d->itemDelegate->rightHandle(index, true);
model()->setData(index, m_d->itemDelegate->unscaledTangent(rightHandle), KisAnimationCurvesModel::RightTangentRole);
}
}
m_d->model->endCommand();
m_d->isAdjustingHandle = false;
m_d->itemDelegate->setHandleAdjustment(QPointF(), m_d->adjustedHandle);
}
}
QAbstractItemView::mouseReleaseEvent(e);
}
void KisAnimationCurvesView::scrollContentsBy(int dx, int dy)
{
m_d->horizontalHeader->setOffset(horizontalScrollBar()->value());
m_d->verticalHeader->setOffset(verticalScrollBar()->value());
scrollDirtyRegion(dx, dy);
viewport()->scroll(dx, dy);
+ viewport()->update();
}
void KisAnimationCurvesView::updateGeometries()
{
int topMargin = qMax(m_d->horizontalHeader->minimumHeight(),
m_d->horizontalHeader->sizeHint().height());
int leftMargin = m_d->verticalHeader->sizeHint().width();
setViewportMargins(leftMargin, topMargin, 0, 0);
QRect viewRect = viewport()->geometry();
m_d->horizontalHeader->setGeometry(leftMargin, 0, viewRect.width(), topMargin);
m_d->verticalHeader->setGeometry(0, topMargin, leftMargin, viewRect.height());
horizontalScrollBar()->setRange(0, m_d->horizontalHeader->length() - viewport()->width());
updateVerticalRange();
QAbstractItemView::updateGeometries();
}
void KisAnimationCurvesView::slotRowsChanged(const QModelIndex &parentIndex, int first, int last)
{
Q_UNUSED(parentIndex);
Q_UNUSED(first);
Q_UNUSED(last);
updateVerticalRange();
viewport()->update();
}
void KisAnimationCurvesView::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
+
updateVerticalRange();
viewport()->update();
+
+ // this forces the horizontal ruler to refresh. Repaint() doesn't do it for some reason
+ // If you remove this, scrubbing the timeline will probably stop updating the indicator
+ m_d->horizontalHeader->resize(m_d->horizontalHeader->width()-1, m_d->horizontalHeader->height());
+ m_d->horizontalHeader->resize(m_d->horizontalHeader->width()+1, m_d->horizontalHeader->height());
}
void KisAnimationCurvesView::slotHeaderDataChanged(Qt::Orientation orientation, int first, int last)
{
Q_UNUSED(orientation);
Q_UNUSED(first);
Q_UNUSED(last);
viewport()->update();
}
void KisAnimationCurvesView::slotHorizontalZoomStarted(qreal staticPoint)
{
m_d->horizontalZoomStillPointIndex =
qIsNaN(staticPoint) ? currentIndex().column() : staticPoint;
const int w = m_d->horizontalHeader->defaultSectionSize();
m_d->horizontalZoomStillPointOriginalOffset =
w * m_d->horizontalZoomStillPointIndex -
horizontalScrollBar()->value();
}
void KisAnimationCurvesView::slotHorizontalZoomLevelChanged(qreal zoomLevel)
{
if (m_d->horizontalHeader->setZoom(zoomLevel)) {
const int w = m_d->horizontalHeader->defaultSectionSize();
horizontalScrollBar()->setValue(w * m_d->horizontalZoomStillPointIndex - m_d->horizontalZoomStillPointOriginalOffset);
viewport()->update();
}
}
void KisAnimationCurvesView::slotVerticalZoomStarted(qreal staticPoint)
{
m_d->verticalZoomStillPoint = qIsNaN(staticPoint) ? 0 : staticPoint;
const float scale = m_d->verticalHeader->scaleFactor();
m_d->verticalZoomStillPointOriginalOffset =
scale * m_d->verticalZoomStillPoint - m_d->verticalHeader->offset();
}
void KisAnimationCurvesView::slotVerticalZoomLevelChanged(qreal zoomLevel)
{
if (!qFuzzyCompare((float)zoomLevel, m_d->verticalHeader->scaleFactor())) {
m_d->verticalHeader->setScale(zoomLevel);
m_d->verticalHeader->setOffset(-zoomLevel * m_d->verticalZoomStillPoint - m_d->verticalZoomStillPointOriginalOffset);
verticalScrollBar()->setValue(m_d->verticalHeader->offset());
viewport()->update();
}
}
void KisAnimationCurvesView::applyConstantMode()
{
m_d->model->beginCommand(kundo2_i18n("Set interpolation mode"));
Q_FOREACH(QModelIndex index, selectedIndexes()) {
m_d->model->setData(index, KisKeyframe::Constant, KisAnimationCurvesModel::InterpolationModeRole);
}
m_d->model->endCommand();
}
void KisAnimationCurvesView::applyLinearMode()
{
m_d->model->beginCommand(kundo2_i18n("Set interpolation mode"));
Q_FOREACH(QModelIndex index, selectedIndexes()) {
m_d->model->setData(index, KisKeyframe::Linear, KisAnimationCurvesModel::InterpolationModeRole);
}
m_d->model->endCommand();
}
void KisAnimationCurvesView::applyBezierMode()
{
m_d->model->beginCommand(kundo2_i18n("Set interpolation mode"));
Q_FOREACH(QModelIndex index, selectedIndexes()) {
m_d->model->setData(index, KisKeyframe::Bezier, KisAnimationCurvesModel::InterpolationModeRole);
}
m_d->model->endCommand();
}
void KisAnimationCurvesView::applySmoothMode()
{
m_d->model->beginCommand(kundo2_i18n("Set interpolation mode"));
Q_FOREACH(QModelIndex index, selectedIndexes()) {
QVector2D leftVisualTangent(m_d->itemDelegate->leftHandle(index, false));
QVector2D rightVisualTangent(m_d->itemDelegate->rightHandle(index, false));
if (leftVisualTangent.lengthSquared() > 0 && rightVisualTangent.lengthSquared() > 0) {
float leftAngle = qAtan2(-leftVisualTangent.y(), -leftVisualTangent.x());
float rightAngle = qAtan2(rightVisualTangent.y(), rightVisualTangent.x());
float angle = (leftAngle + rightAngle) / 2;
QVector2D unit(qCos(angle), qSin(angle));
leftVisualTangent = -unit * QVector2D(leftVisualTangent).length();
rightVisualTangent = unit * QVector2D(rightVisualTangent).length();
QPointF leftTangent = m_d->itemDelegate->unscaledTangent(leftVisualTangent.toPointF());
QPointF rightTangent = m_d->itemDelegate->unscaledTangent(rightVisualTangent.toPointF());
model()->setData(index, leftTangent, KisAnimationCurvesModel::LeftTangentRole);
model()->setData(index, rightTangent, KisAnimationCurvesModel::RightTangentRole);
}
model()->setData(index, KisKeyframe::Smooth, KisAnimationCurvesModel::TangentsModeRole);
}
m_d->model->endCommand();
}
void KisAnimationCurvesView::applySharpMode()
{
m_d->model->beginCommand(kundo2_i18n("Set interpolation mode"));
Q_FOREACH(QModelIndex index, selectedIndexes()) {
model()->setData(index, KisKeyframe::Sharp, KisAnimationCurvesModel::TangentsModeRole);
}
m_d->model->endCommand();
}
void KisAnimationCurvesView::createKeyframe()
{
QModelIndex active = currentIndex();
int channel = active.isValid() ? active.row() : 0;
int time = m_d->model->currentTime();
QModelIndex index = m_d->model->index(channel, time);
qreal value = index.data(KisAnimationCurvesModel::ScalarValueRole).toReal();
m_d->model->setData(index, value, KisAnimationCurvesModel::ScalarValueRole);
}
void KisAnimationCurvesView::removeKeyframes()
{
m_d->model->removeFrames(selectedIndexes());
}
+
void KisAnimationCurvesView::zoomToFit()
{
if (!model()) return;
qreal minimum, maximum;
findExtremes(&minimum, &maximum);
if (minimum == maximum) return;
qreal zoomLevel = (viewport()->height() - 2 * VERTICAL_PADDING) / (maximum - minimum);
qreal offset = -VERTICAL_PADDING - zoomLevel * maximum;
m_d->verticalHeader->setScale(zoomLevel);
m_d->verticalHeader->setOffset(offset);
verticalScrollBar()->setValue(offset);
viewport()->update();
}
diff --git a/plugins/dockers/animation/kis_animation_curves_view.h b/plugins/dockers/animation/kis_animation_curves_view.h
index adbff9f7b9..1b666930ed 100644
--- a/plugins/dockers/animation/kis_animation_curves_view.h
+++ b/plugins/dockers/animation/kis_animation_curves_view.h
@@ -1,100 +1,103 @@
/*
* Copyright (c) 2016 Jouni Pentikäinen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_ANIMATION_CURVES_VIEW_H
#define _KIS_ANIMATION_CURVES_VIEW_H
#include
#include
#include
class KisAction;
class KisZoomButton;
class KisAnimationCurvesView : public QAbstractItemView
{
Q_OBJECT
public:
KisAnimationCurvesView(QWidget *parent);
~KisAnimationCurvesView() override;
void setModel(QAbstractItemModel *model) override;
void setZoomButtons(KisZoomButton *horizontal, KisZoomButton *vertical);
QRect visualRect(const QModelIndex &index) const override;
void scrollTo(const QModelIndex &index, ScrollHint hint) override;
QModelIndex indexAt(const QPoint &point) const override;
protected:
void paintEvent(QPaintEvent *) override;
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
int horizontalOffset() const override;
int verticalOffset() const override;
bool isIndexHidden(const QModelIndex &index) const override;
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
QRegion visualRegionForSelection(const QItemSelection &selection) const override;
void scrollContentsBy(int dx, int dy) override;
void mousePressEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
public Q_SLOTS:
void applyConstantMode();
void applyLinearMode();
void applyBezierMode();
void applySmoothMode();
void applySharpMode();
void createKeyframe();
void removeKeyframes();
void zoomToFit();
void slotScrollerStateChanged(QScroller::State state){KisKineticScroller::updateCursor(this, state);}
protected Q_SLOTS:
void updateGeometries() override;
private Q_SLOTS:
void slotRowsChanged(const QModelIndex &parentIndex, int first, int last);
void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void slotHeaderDataChanged(Qt::Orientation orientation, int first, int last);
void slotHorizontalZoomStarted(qreal staticPoint);
void slotVerticalZoomStarted(qreal staticPoint);
void slotHorizontalZoomLevelChanged(qreal level);
void slotVerticalZoomLevelChanged(qreal level);
private:
struct Private;
const QScopedPointer m_d;
+ void paintFrames(QPainter &painter);
void paintCurves(QPainter &painter, int firstFrame, int lastFrame);
void paintCurve(int channel, int firstFrame, int lastFrame, QPainter &painter);
void paintCurveSegment(QPainter &painter, QPointF pos1, QPointF rightTangent, QPointF leftTangent, QPointF pos2);
void paintKeyframes(QPainter &painter, int firstFrame, int lastFrame);
QModelIndex findNextKeyframeIndex(int channel, int time, int selectionOffset, bool backward);
void findExtremes(qreal *minimum, qreal *maximum);
void updateVerticalRange();
+
+
void startPan(QPoint mousePos);
};
#endif
diff --git a/plugins/dockers/animation/kis_animation_utils.cpp b/plugins/dockers/animation/kis_animation_utils.cpp
index 82a19a0b6e..b436ade6de 100644
--- a/plugins/dockers/animation/kis_animation_utils.cpp
+++ b/plugins/dockers/animation/kis_animation_utils.cpp
@@ -1,354 +1,354 @@
/*
* Copyright (c) 2015 Dmitry Kazakov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_animation_utils.h"
#include "kundo2command.h"
#include "kis_algebra_2d.h"
#include "kis_image.h"
#include "kis_node.h"
#include "kis_keyframe_channel.h"
#include "kis_post_execution_undo_adapter.h"
#include "kis_global.h"
#include "kis_tool_utils.h"
#include "kis_image_animation_interface.h"
#include "kis_command_utils.h"
#include "kis_processing_applicator.h"
#include "kis_transaction.h"
namespace KisAnimationUtils {
- const QString addFrameActionName = i18n("New Frame");
- const QString duplicateFrameActionName = i18n("Copy Frame");
- const QString removeFrameActionName = i18n("Remove Frame");
- const QString removeFramesActionName = i18n("Remove Frames");
const QString lazyFrameCreationActionName = i18n("Auto Frame Mode");
const QString dropFramesActionName = i18n("Drop Frames");
- const QString showLayerActionName = i18n("Show in Timeline");
const QString newLayerActionName = i18n("New Layer");
const QString addExistingLayerActionName = i18n("Add Existing Layer");
const QString removeLayerActionName = i18n("Remove Layer");
- const QString addOpacityKeyframeActionName = i18n("Add opacity keyframe");
const QString addTransformKeyframeActionName = i18n("Add transform keyframe");
- const QString removeOpacityKeyframeActionName = i18n("Remove opacity keyframe");
const QString removeTransformKeyframeActionName = i18n("Remove transform keyframe");
KUndo2Command* createKeyframeCommand(KisImageSP image, KisNodeSP node, const QString &channelId, int time, bool copy, KUndo2Command *parentCommand) {
KUndo2Command *cmd = new KisCommandUtils::LambdaCommand(
copy ? kundo2_i18n("Copy Keyframe") :
kundo2_i18n("Add Keyframe"),
parentCommand,
[image, node, channelId, time, copy] () mutable -> KUndo2Command* {
bool result = false;
QScopedPointer cmd(new KUndo2Command());
KisKeyframeChannel *channel = node->getKeyframeChannel(channelId);
+ quint8 originalOpacity = node->opacity();
bool createdChannel = false;
if (!channel) {
node->enableAnimation();
channel = node->getKeyframeChannel(channelId, true);
if (!channel) return nullptr;
createdChannel = true;
}
if (copy) {
if (!channel->keyframeAt(time)) {
KisKeyframeSP srcFrame = channel->activeKeyframeAt(time);
channel->copyKeyframe(srcFrame, time, cmd.data());
result = true;
}
} else {
if (channel->keyframeAt(time) && !createdChannel) {
if (image->animationInterface()->currentTime() == time && channelId == KisKeyframeChannel::Content.id()) {
//shortcut: clearing the image instead
KisPaintDeviceSP device = node->paintDevice();
if (device) {
const QRect dirtyRect = device->extent();
KisTransaction transaction(kundo2_i18n("Clear"), device, cmd.data());
device->clear();
(void) transaction.endAndTake(); // saved as 'parent'
node->setDirty(dirtyRect);
result = true;
}
}
} else {
channel->addKeyframe(time, cmd.data());
result = true;
}
}
+ // when a new opacity keyframe is created, the opacity is set to 0
+ // this makes sure to use the opacity that was previously used
+ // maybe there is a better way to do this
+ node->setOpacity(originalOpacity);
+
return result ? new KisCommandUtils::SkipFirstRedoWrapper(cmd.take()) : nullptr;
});
return cmd;
}
- void createKeyframeLazy(KisImageSP image, KisNodeSP node, const QString &channelId, int time, bool copy) {
+ void createKeyframeLazy(KisImageSP image, KisNodeSP node, const QString &channelId, int time, bool copy)
+ {
KUndo2Command *cmd = createKeyframeCommand(image, node, channelId, time, copy);
KisProcessingApplicator::runSingleCommandStroke(image, cmd,
KisStrokeJobData::BARRIER,
KisStrokeJobData::EXCLUSIVE);
}
void removeKeyframes(KisImageSP image, const FrameItemList &frames) {
KIS_SAFE_ASSERT_RECOVER_RETURN(!image->locked());
KUndo2Command *cmd = new KisCommandUtils::LambdaCommand(
kundo2_i18np("Remove Keyframe",
"Remove Keyframes",
frames.size()),
[image, frames] () {
bool result = false;
QScopedPointer cmd(new KUndo2Command());
Q_FOREACH (const FrameItem &item, frames) {
const int time = item.time;
KisNodeSP node = item.node;
KisKeyframeChannel *channel = 0;
if (node) {
channel = node->getKeyframeChannel(item.channel);
}
if (!channel) continue;
KisKeyframeSP keyframe = channel->keyframeAt(time);
if (!keyframe) continue;
channel->deleteKeyframe(keyframe, cmd.data());
result = true;
}
return result ? new KisCommandUtils::SkipFirstRedoWrapper(cmd.take()) : 0;
});
KisProcessingApplicator::runSingleCommandStroke(image, cmd,
KisStrokeJobData::BARRIER,
KisStrokeJobData::EXCLUSIVE);
}
void removeKeyframe(KisImageSP image, KisNodeSP node, const QString &channel, int time) {
QVector frames;
frames << FrameItem(node, channel, time);
removeKeyframes(image, frames);
}
struct LessOperator {
LessOperator(const QPoint &offset)
: m_columnCoeff(-KisAlgebra2D::signPZ(offset.x())),
m_rowCoeff(-1000000 * KisAlgebra2D::signZZ(offset.y()))
{
}
bool operator()(const QModelIndex &lhs, const QModelIndex &rhs) {
return
m_columnCoeff * lhs.column() + m_rowCoeff * lhs.row() <
m_columnCoeff * rhs.column() + m_rowCoeff * rhs.row();
}
private:
int m_columnCoeff;
int m_rowCoeff;
};
void sortPointsForSafeMove(QModelIndexList *points, const QPoint &offset)
{
std::sort(points->begin(), points->end(), LessOperator(offset));
}
bool supportsContentFrames(KisNodeSP node)
{
return node->inherits("KisPaintLayer") || node->inherits("KisFilterMask") || node->inherits("KisTransparencyMask") || node->inherits("KisSelectionBasedLayer");
}
void swapOneFrameItem(const FrameItem &src, const FrameItem &dst, KUndo2Command *parentCommand)
{
const int srcTime = src.time;
KisNodeSP srcNode = src.node;
KisKeyframeChannel *srcChannel = srcNode->getKeyframeChannel(src.channel);
const int dstTime = dst.time;
KisNodeSP dstNode = dst.node;
KisKeyframeChannel *dstChannel = dstNode->getKeyframeChannel(dst.channel, true);
if (srcNode == dstNode) {
if (!srcChannel) return; // TODO: add warning!
srcChannel->swapFrames(srcTime, dstTime, parentCommand);
} else {
if (!srcChannel || !dstChannel) return; // TODO: add warning!
dstChannel->swapExternalKeyframe(srcChannel, srcTime, dstTime, parentCommand);
}
}
void moveOneFrameItem(const FrameItem &src, const FrameItem &dst, bool copy, bool moveEmptyFrames, KUndo2Command *parentCommand)
{
const int srcTime = src.time;
KisNodeSP srcNode = src.node;
KisKeyframeChannel *srcChannel = srcNode->getKeyframeChannel(src.channel);
const int dstTime = dst.time;
KisNodeSP dstNode = dst.node;
KisKeyframeChannel *dstChannel = dstNode->getKeyframeChannel(dst.channel, true);
if (srcNode == dstNode) {
if (!srcChannel) return; // TODO: add warning!
KisKeyframeSP srcKeyframe = srcChannel->keyframeAt(srcTime);
KisKeyframeSP dstKeyFrame = srcChannel->keyframeAt(dstTime);
if (srcKeyframe) {
if (copy) {
srcChannel->copyKeyframe(srcKeyframe, dstTime, parentCommand);
} else {
srcChannel->moveKeyframe(srcKeyframe, dstTime, parentCommand);
}
} else {
if (dstKeyFrame && moveEmptyFrames && !copy) {
//Destination is effectively replaced by an empty frame.
dstChannel->deleteKeyframe(dstKeyFrame, parentCommand);
}
}
} else {
if (!srcChannel || !dstChannel) return; // TODO: add warning!
KisKeyframeSP srcKeyframe = srcChannel->keyframeAt(srcTime);
if (!srcKeyframe) return; // TODO: add warning!
dstChannel->copyExternalKeyframe(srcChannel, srcTime, dstTime, parentCommand);
if (!copy) {
srcChannel->deleteKeyframe(srcKeyframe, parentCommand);
}
}
}
KUndo2Command* createMoveKeyframesCommand(const FrameItemList &srcFrames,
const FrameItemList &dstFrames,
bool copy,
bool moveEmpty,
KUndo2Command *parentCommand)
{
FrameMovePairList srcDstPairs;
for (int i = 0; i < srcFrames.size(); i++) {
srcDstPairs << std::make_pair(srcFrames[i], dstFrames[i]);
}
return createMoveKeyframesCommand(srcDstPairs, copy, moveEmpty, parentCommand);
}
KUndo2Command* createMoveKeyframesCommand(const FrameMovePairList &srcDstPairs,
bool copy,
bool moveEmptyFrames,
KUndo2Command *parentCommand)
{
KUndo2Command *cmd = new KisCommandUtils::LambdaCommand(
!copy ?
kundo2_i18np("Move Keyframe",
"Move %1 Keyframes",
srcDstPairs.size()) :
kundo2_i18np("Copy Keyframe",
"Copy %1 Keyframes",
srcDstPairs.size()),
parentCommand,
[srcDstPairs, copy, moveEmptyFrames] () -> KUndo2Command* {
bool result = false;
QScopedPointer cmd(new KUndo2Command());
using MoveChain = QList;
QHash moveMap;
Q_FOREACH (const FrameMovePair &pair, srcDstPairs) {
moveMap.insert(pair.first, {pair.second});
}
auto it = moveMap.begin();
while (it != moveMap.end()) {
MoveChain &chain = it.value();
const FrameItem &previousFrame = chain.last();
auto tailIt = moveMap.find(previousFrame);
if (tailIt == it || tailIt == moveMap.end()) {
++it;
continue;
}
chain.append(tailIt.value());
tailIt = moveMap.erase(tailIt);
// no incrementing! we are going to check the new tail now!
}
for (it = moveMap.begin(); it != moveMap.end(); ++it) {
MoveChain &chain = it.value();
chain.prepend(it.key());
KIS_SAFE_ASSERT_RECOVER(chain.size() > 1) { continue; }
bool isCycle = false;
if (chain.last() == chain.first()) {
isCycle = true;
chain.takeLast();
}
auto frameIt = chain.rbegin();
FrameItem dstItem = *frameIt++;
while (frameIt != chain.rend()) {
FrameItem srcItem = *frameIt++;
if (!isCycle) {
moveOneFrameItem(srcItem, dstItem, copy, moveEmptyFrames, cmd.data());
} else {
swapOneFrameItem(srcItem, dstItem, cmd.data());
}
dstItem = srcItem;
result = true;
}
}
return result ? new KisCommandUtils::SkipFirstRedoWrapper(cmd.take()) : 0;
});
return cmd;
}
QDebug operator<<(QDebug dbg, const FrameItem &item)
{
dbg.nospace() << "FrameItem(" << item.node->name() << ", " << item.channel << ", " << item.time << ")";
return dbg.space();
}
}
diff --git a/plugins/dockers/animation/kis_animation_utils.h b/plugins/dockers/animation/kis_animation_utils.h
index aa86fc14a2..0cf8d07720 100644
--- a/plugins/dockers/animation/kis_animation_utils.h
+++ b/plugins/dockers/animation/kis_animation_utils.h
@@ -1,104 +1,99 @@
/*
* Copyright (c) 2015 Dmitry Kazakov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __KIS_ANIMATION_UTILS_H
#define __KIS_ANIMATION_UTILS_H
#include "kis_types.h"
#include
#include
#include
namespace KisAnimationUtils
{
KUndo2Command* createKeyframeCommand(KisImageSP image, KisNodeSP node, const QString &channelId, int time, bool copy, KUndo2Command *parentCommand = 0);
void createKeyframeLazy(KisImageSP image, KisNodeSP node, const QString &channel, int time, bool copy);
struct KRITAANIMATIONDOCKER_EXPORT FrameItem : public boost::equality_comparable
{
FrameItem() : time(-1) {}
FrameItem(KisNodeSP _node, const QString &_channel, int _time) : node(_node), channel(_channel), time(_time) {}
bool operator==(const FrameItem &rhs) const {
return rhs.node == node && rhs.channel == channel && rhs.time == time;
}
KisNodeSP node;
QString channel;
int time;
};
KRITAANIMATIONDOCKER_EXPORT QDebug operator<<(QDebug dbg, const FrameItem &item);
inline uint qHash(const FrameItem &item)
{
return ::qHash(item.node.data()) + ::qHash(item.channel) + ::qHash(item.time);
}
typedef QVector FrameItemList;
typedef std::pair FrameMovePair;
typedef QVector FrameMovePairList;
void removeKeyframes(KisImageSP image, const FrameItemList &frames);
void removeKeyframe(KisImageSP image, KisNodeSP node, const QString &channel, int time);
void sortPointsForSafeMove(QModelIndexList *points, const QPoint &offset);
KUndo2Command* createMoveKeyframesCommand(const FrameItemList &srcFrames, const FrameItemList &dstFrames,
bool copy, bool moveEmpty, KUndo2Command *parentCommand = 0);
/**
* @brief implements safe moves of the frames (even if there are cycling move dependencies)
* @param movePairs the jobs for the moves
* @param copy shows if the frames should be copied or not
* @param moveEmpty allows an empty frame to replace a populated one
* @param parentCommand the command that should be a parent of the created command
* @return a created undo command
*/
KRITAANIMATIONDOCKER_EXPORT
KUndo2Command* createMoveKeyframesCommand(const FrameMovePairList &movePairs,
bool copy, bool moveEmptyFrames, KUndo2Command *parentCommand = 0);
bool supportsContentFrames(KisNodeSP node);
- extern const QString addFrameActionName;
- extern const QString duplicateFrameActionName;
- extern const QString removeFrameActionName;
- extern const QString removeFramesActionName;
extern const QString lazyFrameCreationActionName;
extern const QString dropFramesActionName;
- extern const QString showLayerActionName;
extern const QString newLayerActionName;
extern const QString addExistingLayerActionName;
extern const QString removeLayerActionName;
extern const QString addOpacityKeyframeActionName;
extern const QString addTransformKeyframeActionName;
extern const QString removeOpacityKeyframeActionName;
extern const QString removeTransformKeyframeActionName;
};
#endif /* __KIS_ANIMATION_UTILS_H */
diff --git a/plugins/dockers/animation/timeline_frames_view.cpp b/plugins/dockers/animation/timeline_frames_view.cpp
index 391ce050b3..7e71d4e6a6 100644
--- a/plugins/dockers/animation/timeline_frames_view.cpp
+++ b/plugins/dockers/animation/timeline_frames_view.cpp
@@ -1,1547 +1,1557 @@
/*
* Copyright (c) 2015 Dmitry Kazakov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "timeline_frames_view.h"
#include "timeline_frames_model.h"
#include "timeline_ruler_header.h"
#include "timeline_layers_header.h"
#include "timeline_insert_keyframe_dialog.h"
#include "timeline_frames_item_delegate.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "config-qtmultimedia.h"
#include "KSharedConfig"
#include "KisKineticScroller.h"
#include "kis_zoom_button.h"
#include "kis_icon_utils.h"
#include "kis_animation_utils.h"
#include "kis_custom_modifiers_catcher.h"
#include "kis_action.h"
#include "kis_signal_compressor.h"
#include "kis_time_range.h"
#include "kis_color_label_selector_widget.h"
#include "kis_keyframe_channel.h"
#include "kis_slider_spin_box.h"
#include
#include
#include
#include
#include
typedef QPair QItemViewPaintPair;
typedef QList QItemViewPaintPairs;
struct TimelineFramesView::Private
{
Private(TimelineFramesView *_q)
: q(_q),
fps(1),
zoomStillPointIndex(-1),
zoomStillPointOriginalOffset(0),
dragInProgress(false),
dragWasSuccessful(false),
modifiersCatcher(0),
selectionChangedCompressor(300, KisSignalCompressor::FIRST_INACTIVE)
{}
TimelineFramesView *q;
TimelineFramesModel *model;
TimelineRulerHeader *horizontalRuler;
TimelineLayersHeader *layersHeader;
int fps;
int zoomStillPointIndex;
int zoomStillPointOriginalOffset;
QPoint initialDragPanValue;
QPoint initialDragPanPos;
QToolButton *addLayersButton;
KisAction *showHideLayerAction;
QToolButton *audioOptionsButton;
KisColorLabelSelectorWidget *colorSelector;
QWidgetAction *colorSelectorAction;
KisColorLabelSelectorWidget *multiframeColorSelector;
QWidgetAction *multiframeColorSelectorAction;
QMenu *audioOptionsMenu;
QAction *openAudioAction;
QAction *audioMuteAction;
KisSliderSpinBox *volumeSlider;
QMenu *layerEditingMenu;
QMenu *existingLayersMenu;
TimelineInsertKeyframeDialog *insertKeyframeDialog;
KisZoomButton *zoomDragButton;
bool dragInProgress;
bool dragWasSuccessful;
KisCustomModifiersCatcher *modifiersCatcher;
QPoint lastPressedPosition;
Qt::KeyboardModifiers lastPressedModifier;
KisSignalCompressor selectionChangedCompressor;
QStyleOptionViewItem viewOptionsV4() const;
QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;
QPixmap renderToPixmap(const QModelIndexList &indexes, QRect *r) const;
KoIconToolTip tip;
KisActionManager *actionMan = 0;
};
TimelineFramesView::TimelineFramesView(QWidget *parent)
: QTableView(parent),
m_d(new Private(this))
{
m_d->modifiersCatcher = new KisCustomModifiersCatcher(this);
m_d->modifiersCatcher->addModifier("pan-zoom", Qt::Key_Space);
m_d->modifiersCatcher->addModifier("offset-frame", Qt::Key_Alt);
setCornerButtonEnabled(false);
setSelectionBehavior(QAbstractItemView::SelectItems);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setItemDelegate(new TimelineFramesItemDelegate(this));
setDragEnabled(true);
setDragDropMode(QAbstractItemView::DragDrop);
setAcceptDrops(true);
setDropIndicatorShown(true);
setDefaultDropAction(Qt::MoveAction);
m_d->horizontalRuler = new TimelineRulerHeader(this);
this->setHorizontalHeader(m_d->horizontalRuler);
connect(m_d->horizontalRuler, SIGNAL(sigInsertColumnLeft()), SLOT(slotInsertKeyframeColumnLeft()));
connect(m_d->horizontalRuler, SIGNAL(sigInsertColumnRight()), SLOT(slotInsertKeyframeColumnRight()));
connect(m_d->horizontalRuler, SIGNAL(sigInsertMultipleColumns()), SLOT(slotInsertMultipleKeyframeColumns()));
connect(m_d->horizontalRuler, SIGNAL(sigRemoveColumns()), SLOT(slotRemoveSelectedColumns()));
connect(m_d->horizontalRuler, SIGNAL(sigRemoveColumnsAndShift()), SLOT(slotRemoveSelectedColumnsAndShift()));
connect(m_d->horizontalRuler, SIGNAL(sigInsertHoldColumns()), SLOT(slotInsertHoldFrameColumn()));
connect(m_d->horizontalRuler, SIGNAL(sigRemoveHoldColumns()), SLOT(slotRemoveHoldFrameColumn()));
connect(m_d->horizontalRuler, SIGNAL(sigInsertHoldColumnsCustom()), SLOT(slotInsertMultipleHoldFrameColumns()));
connect(m_d->horizontalRuler, SIGNAL(sigRemoveHoldColumnsCustom()), SLOT(slotRemoveMultipleHoldFrameColumns()));
connect(m_d->horizontalRuler, SIGNAL(sigMirrorColumns()), SLOT(slotMirrorColumns()));
connect(m_d->horizontalRuler, SIGNAL(sigCopyColumns()), SLOT(slotCopyColumns()));
connect(m_d->horizontalRuler, SIGNAL(sigCutColumns()), SLOT(slotCutColumns()));
connect(m_d->horizontalRuler, SIGNAL(sigPasteColumns()), SLOT(slotPasteColumns()));
m_d->layersHeader = new TimelineLayersHeader(this);
m_d->layersHeader->setSectionResizeMode(QHeaderView::Fixed);
m_d->layersHeader->setDefaultSectionSize(24);
m_d->layersHeader->setMinimumWidth(60);
m_d->layersHeader->setHighlightSections(true);
this->setVerticalHeader(m_d->layersHeader);
connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), SLOT(slotUpdateInfiniteFramesCount()));
connect(horizontalScrollBar(), SIGNAL(sliderReleased()), SLOT(slotUpdateInfiniteFramesCount()));
/********** New Layer Menu ***********************************************************/
m_d->addLayersButton = new QToolButton(this);
m_d->addLayersButton->setAutoRaise(true);
m_d->addLayersButton->setIcon(KisIconUtils::loadIcon("addlayer"));
m_d->addLayersButton->setIconSize(QSize(20, 20));
m_d->addLayersButton->setPopupMode(QToolButton::InstantPopup);
m_d->layerEditingMenu = new QMenu(this);
m_d->layerEditingMenu->addAction(KisAnimationUtils::newLayerActionName, this, SLOT(slotAddNewLayer()));
m_d->existingLayersMenu = m_d->layerEditingMenu->addMenu(KisAnimationUtils::addExistingLayerActionName);
m_d->layerEditingMenu->addSeparator();
m_d->layerEditingMenu->addAction(KisAnimationUtils::removeLayerActionName, this, SLOT(slotRemoveLayer()));
connect(m_d->existingLayersMenu, SIGNAL(aboutToShow()), SLOT(slotUpdateLayersMenu()));
connect(m_d->existingLayersMenu, SIGNAL(triggered(QAction*)), SLOT(slotAddExistingLayer(QAction*)));
connect(m_d->layersHeader, SIGNAL(sigRequestContextMenu(QPoint)), SLOT(slotLayerContextMenuRequested(QPoint)));
m_d->addLayersButton->setMenu(m_d->layerEditingMenu);
/********** Audio Channel Menu *******************************************************/
m_d->audioOptionsButton = new QToolButton(this);
m_d->audioOptionsButton->setAutoRaise(true);
m_d->audioOptionsButton->setIcon(KisIconUtils::loadIcon("audio-none"));
m_d->audioOptionsButton->setIconSize(QSize(20, 20)); // very small on windows if not explicitly set
m_d->audioOptionsButton->setPopupMode(QToolButton::InstantPopup);
m_d->audioOptionsMenu = new QMenu(this);
#ifndef HAVE_QT_MULTIMEDIA
m_d->audioOptionsMenu->addSection(i18nc("@item:inmenu", "Audio playback is not supported in this build!"));
#endif
m_d->openAudioAction= new QAction("XXX", this);
connect(m_d->openAudioAction, SIGNAL(triggered()), this, SLOT(slotSelectAudioChannelFile()));
m_d->audioOptionsMenu->addAction(m_d->openAudioAction);
m_d->audioMuteAction = new QAction(i18nc("@item:inmenu", "Mute"), this);
m_d->audioMuteAction->setCheckable(true);
connect(m_d->audioMuteAction, SIGNAL(triggered(bool)), SLOT(slotAudioChannelMute(bool)));
m_d->audioOptionsMenu->addAction(m_d->audioMuteAction);
m_d->audioOptionsMenu->addAction(i18nc("@item:inmenu", "Remove audio"), this, SLOT(slotAudioChannelRemove()));
m_d->audioOptionsMenu->addSeparator();
m_d->volumeSlider = new KisSliderSpinBox(this);
m_d->volumeSlider->setRange(0, 100);
m_d->volumeSlider->setSuffix("%");
m_d->volumeSlider->setPrefix(i18nc("@item:inmenu, slider", "Volume:"));
m_d->volumeSlider->setSingleStep(1);
m_d->volumeSlider->setPageStep(10);
m_d->volumeSlider->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
connect(m_d->volumeSlider, SIGNAL(valueChanged(int)), SLOT(slotAudioVolumeChanged(int)));
QWidgetAction *volumeAction = new QWidgetAction(m_d->audioOptionsMenu);
volumeAction->setDefaultWidget(m_d->volumeSlider);
m_d->audioOptionsMenu->addAction(volumeAction);
m_d->audioOptionsButton->setMenu(m_d->audioOptionsMenu);
/********** Frame Editing Context Menu ***********************************************/
m_d->colorSelector = new KisColorLabelSelectorWidget(this);
m_d->colorSelectorAction = new QWidgetAction(this);
m_d->colorSelectorAction->setDefaultWidget(m_d->colorSelector);
connect(m_d->colorSelector, &KisColorLabelSelectorWidget::currentIndexChanged, this, &TimelineFramesView::slotColorLabelChanged);
m_d->multiframeColorSelector = new KisColorLabelSelectorWidget(this);
m_d->multiframeColorSelectorAction = new QWidgetAction(this);
m_d->multiframeColorSelectorAction->setDefaultWidget(m_d->multiframeColorSelector);
connect(m_d->multiframeColorSelector, &KisColorLabelSelectorWidget::currentIndexChanged, this, &TimelineFramesView::slotColorLabelChanged);
/********** Insert Keyframes Dialog **************************************************/
m_d->insertKeyframeDialog = new TimelineInsertKeyframeDialog(this);
/********** Zoom Button **************************************************************/
m_d->zoomDragButton = new KisZoomButton(this);
m_d->zoomDragButton->setAutoRaise(true);
m_d->zoomDragButton->setIcon(KisIconUtils::loadIcon("zoom-horizontal"));
m_d->zoomDragButton->setIconSize(QSize(20, 20)); // this icon is very small on windows if no explicitly set
m_d->zoomDragButton->setToolTip(i18nc("@info:tooltip", "Zoom Timeline. Hold down and drag left or right."));
m_d->zoomDragButton->setPopupMode(QToolButton::InstantPopup);
connect(m_d->zoomDragButton, SIGNAL(zoomLevelChanged(qreal)), SLOT(slotZoomButtonChanged(qreal)));
connect(m_d->zoomDragButton, SIGNAL(zoomStarted(qreal)), SLOT(slotZoomButtonPressed(qreal)));
setFramesPerSecond(12);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
{
QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this);
if( scroller ) {
connect(scroller, SIGNAL(stateChanged(QScroller::State)),
this, SLOT(slotScrollerStateChanged(QScroller::State)));
}
}
connect(&m_d->selectionChangedCompressor, SIGNAL(timeout()),
SLOT(slotSelectionChanged()));
connect(&m_d->selectionChangedCompressor, SIGNAL(timeout()),
SLOT(slotUpdateFrameActions()));
{
QClipboard *cb = QApplication::clipboard();
connect(cb, SIGNAL(dataChanged()), SLOT(slotUpdateFrameActions()));
}
}
TimelineFramesView::~TimelineFramesView()
{
}
void TimelineFramesView::setShowInTimeline(KisAction *action)
{
m_d->showHideLayerAction = action;
m_d->layerEditingMenu->addAction(m_d->showHideLayerAction);
}
void TimelineFramesView::setActionManager(KisActionManager *actionManager)
{
m_d->actionMan = actionManager;
m_d->horizontalRuler->setActionManager(actionManager);
if (actionManager) {
KisAction *action = 0;
action = m_d->actionMan->createAction("add_blank_frame");
connect(action, SIGNAL(triggered()), SLOT(slotAddBlankFrame()));
action = m_d->actionMan->createAction("add_duplicate_frame");
connect(action, SIGNAL(triggered()), SLOT(slotAddDuplicateFrame()));
action = m_d->actionMan->createAction("insert_keyframe_left");
connect(action, SIGNAL(triggered()), SLOT(slotInsertKeyframeLeft()));
action = m_d->actionMan->createAction("insert_keyframe_right");
connect(action, SIGNAL(triggered()), SLOT(slotInsertKeyframeRight()));
action = m_d->actionMan->createAction("insert_multiple_keyframes");
connect(action, SIGNAL(triggered()), SLOT(slotInsertMultipleKeyframes()));
action = m_d->actionMan->createAction("remove_frames_and_pull");
connect(action, SIGNAL(triggered()), SLOT(slotRemoveSelectedFramesAndShift()));
action = m_d->actionMan->createAction("remove_frames");
connect(action, SIGNAL(triggered()), SLOT(slotRemoveSelectedFrames()));
action = m_d->actionMan->createAction("insert_hold_frame");
connect(action, SIGNAL(triggered()), SLOT(slotInsertHoldFrame()));
action = m_d->actionMan->createAction("insert_multiple_hold_frames");
connect(action, SIGNAL(triggered()), SLOT(slotInsertMultipleHoldFrames()));
action = m_d->actionMan->createAction("remove_hold_frame");
connect(action, SIGNAL(triggered()), SLOT(slotRemoveHoldFrame()));
action = m_d->actionMan->createAction("remove_multiple_hold_frames");
connect(action, SIGNAL(triggered()), SLOT(slotRemoveMultipleHoldFrames()));
action = m_d->actionMan->createAction("mirror_frames");
connect(action, SIGNAL(triggered()), SLOT(slotMirrorFrames()));
action = m_d->actionMan->createAction("copy_frames_to_clipboard");
connect(action, SIGNAL(triggered()), SLOT(slotCopyFrames()));
action = m_d->actionMan->createAction("cut_frames_to_clipboard");
connect(action, SIGNAL(triggered()), SLOT(slotCutFrames()));
action = m_d->actionMan->createAction("paste_frames_from_clipboard");
connect(action, SIGNAL(triggered()), SLOT(slotPasteFrames()));
action = m_d->actionMan->createAction("set_start_time");
connect(action, SIGNAL(triggered()), SLOT(slotSetStartTimeToCurrentPosition()));
action = m_d->actionMan->createAction("set_end_time");
connect(action, SIGNAL(triggered()), SLOT(slotSetEndTimeToCurrentPosition()));
action = m_d->actionMan->createAction("update_playback_range");
connect(action, SIGNAL(triggered()), SLOT(slotUpdatePlackbackRange()));
}
}
void resizeToMinimalSize(QAbstractButton *w, int minimalSize) {
QSize buttonSize = w->sizeHint();
if (buttonSize.height() > minimalSize) {
buttonSize = QSize(minimalSize, minimalSize);
}
w->resize(buttonSize);
}
void TimelineFramesView::updateGeometries()
{
QTableView::updateGeometries();
const int availableHeight = m_d->horizontalRuler->height();
const int margin = 2;
const int minimalSize = availableHeight - 2 * margin;
resizeToMinimalSize(m_d->addLayersButton, minimalSize);
resizeToMinimalSize(m_d->audioOptionsButton, minimalSize);
resizeToMinimalSize(m_d->zoomDragButton, minimalSize);
int x = 2 * margin;
int y = (availableHeight - minimalSize) / 2;
m_d->addLayersButton->move(x, 2 * y);
m_d->audioOptionsButton->move(x + minimalSize + 2 * margin, 2 * y);
const int availableWidth = m_d->layersHeader->width();
x = availableWidth - margin - minimalSize;
m_d->zoomDragButton->move(x, 2 * y);
}
void TimelineFramesView::setModel(QAbstractItemModel *model)
{
TimelineFramesModel *framesModel = qobject_cast(model);
m_d->model = framesModel;
QTableView::setModel(model);
connect(m_d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
this, SLOT(slotHeaderDataChanged(Qt::Orientation,int,int)));
connect(m_d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(slotDataChanged(QModelIndex,QModelIndex)));
connect(m_d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(slotReselectCurrentIndex()));
connect(m_d->model, SIGNAL(sigInfiniteTimelineUpdateNeeded()),
this, SLOT(slotUpdateInfiniteFramesCount()));
connect(m_d->model, SIGNAL(sigAudioChannelChanged()),
this, SLOT(slotUpdateAudioActions()));
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
&m_d->selectionChangedCompressor, SLOT(start()));
connect(m_d->model, SIGNAL(sigEnsureRowVisible(int)), SLOT(slotEnsureRowVisible(int)));
slotUpdateAudioActions();
}
void TimelineFramesView::setFramesPerSecond(int fps)
{
m_d->fps = fps;
m_d->horizontalRuler->setFramePerSecond(fps);
// For some reason simple update sometimes doesn't work here, so
// reset the whole header
//
// m_d->horizontalRuler->reset();
}
void TimelineFramesView::slotZoomButtonPressed(qreal staticPoint)
{
m_d->zoomStillPointIndex =
qIsNaN(staticPoint) ? currentIndex().column() : staticPoint;
const int w = m_d->horizontalRuler->defaultSectionSize();
m_d->zoomStillPointOriginalOffset =
w * m_d->zoomStillPointIndex -
horizontalScrollBar()->value();
}
void TimelineFramesView::slotZoomButtonChanged(qreal zoomLevel)
{
if (m_d->horizontalRuler->setZoom(zoomLevel)) {
slotUpdateInfiniteFramesCount();
const int w = m_d->horizontalRuler->defaultSectionSize();
horizontalScrollBar()->setValue(w * m_d->zoomStillPointIndex - m_d->zoomStillPointOriginalOffset);
viewport()->update();
}
}
void TimelineFramesView::slotColorLabelChanged(int label)
{
Q_FOREACH(QModelIndex index, selectedIndexes()) {
m_d->model->setData(index, label, TimelineFramesModel::FrameColorLabelIndexRole);
}
KisImageConfig(false).setDefaultFrameColorLabel(label);
}
void TimelineFramesView::slotSelectAudioChannelFile()
{
if (!m_d->model) return;
QString defaultDir = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
const QString currentFile = m_d->model->audioChannelFileName();
QDir baseDir = QFileInfo(currentFile).absoluteDir();
if (baseDir.exists()) {
defaultDir = baseDir.absolutePath();
}
const QString result = KisImportExportManager::askForAudioFileName(defaultDir, this);
const QFileInfo info(result);
if (info.exists()) {
m_d->model->setAudioChannelFileName(info.absoluteFilePath());
}
}
void TimelineFramesView::slotAudioChannelMute(bool value)
{
if (!m_d->model) return;
if (value != m_d->model->isAudioMuted()) {
m_d->model->setAudioMuted(value);
}
}
void TimelineFramesView::slotUpdateIcons()
{
m_d->addLayersButton->setIcon(KisIconUtils::loadIcon("addlayer"));
m_d->audioOptionsButton->setIcon(KisIconUtils::loadIcon("audio-none"));
m_d->zoomDragButton->setIcon(KisIconUtils::loadIcon("zoom-horizontal"));
}
void TimelineFramesView::slotAudioChannelRemove()
{
if (!m_d->model) return;
m_d->model->setAudioChannelFileName(QString());
}
void TimelineFramesView::slotUpdateAudioActions()
{
if (!m_d->model) return;
const QString currentFile = m_d->model->audioChannelFileName();
if (currentFile.isEmpty()) {
m_d->openAudioAction->setText(i18nc("@item:inmenu", "Open audio..."));
} else {
QFileInfo info(currentFile);
m_d->openAudioAction->setText(i18nc("@item:inmenu", "Change audio (%1)...", info.fileName()));
}
m_d->audioMuteAction->setChecked(m_d->model->isAudioMuted());
QIcon audioIcon;
if (currentFile.isEmpty()) {
audioIcon = KisIconUtils::loadIcon("audio-none");
} else {
if (m_d->model->isAudioMuted()) {
audioIcon = KisIconUtils::loadIcon("audio-volume-mute");
} else {
audioIcon = KisIconUtils::loadIcon("audio-volume-high");
}
}
m_d->audioOptionsButton->setIcon(audioIcon);
m_d->volumeSlider->setEnabled(!m_d->model->isAudioMuted());
KisSignalsBlocker b(m_d->volumeSlider);
m_d->volumeSlider->setValue(qRound(m_d->model->audioVolume() * 100.0));
}
void TimelineFramesView::slotAudioVolumeChanged(int value)
{
m_d->model->setAudioVolume(qreal(value) / 100.0);
}
void TimelineFramesView::slotUpdateInfiniteFramesCount()
{
if (horizontalScrollBar()->isSliderDown()) return;
const int sectionWidth = m_d->horizontalRuler->defaultSectionSize();
const int calculatedIndex =
(horizontalScrollBar()->value() +
m_d->horizontalRuler->width() - 1) / sectionWidth;
m_d->model->setLastVisibleFrame(calculatedIndex);
}
void TimelineFramesView::slotScrollerStateChanged( QScroller::State state ) {
KisKineticScroller::updateCursor(this, state);
}
void TimelineFramesView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
{
QTableView::currentChanged(current, previous);
if (previous.column() != current.column()) {
m_d->model->setData(previous, false, TimelineFramesModel::ActiveFrameRole);
m_d->model->setData(current, true, TimelineFramesModel::ActiveFrameRole);
}
}
QItemSelectionModel::SelectionFlags TimelineFramesView::selectionCommand(const QModelIndex &index,
const QEvent *event) const
{
// WARNING: Copy-pasted from KisNodeView! Please keep in sync!
/**
* Qt has a bug: when we Ctrl+click on an item, the item's
* selections gets toggled on mouse *press*, whereas usually it is
* done on mouse *release*. Therefore the user cannot do a
* Ctrl+D&D with the default configuration. This code fixes the
* problem by manually returning QItemSelectionModel::NoUpdate
* flag when the user clicks on an item and returning
* QItemSelectionModel::Toggle on release.
*/
if (event &&
(event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease) &&
index.isValid()) {
const QMouseEvent *mevent = static_cast(event);
if (mevent->button() == Qt::RightButton &&
selectionModel()->selectedIndexes().contains(index)) {
// Allow calling context menu for multiple layers
return QItemSelectionModel::NoUpdate;
}
if (event->type() == QEvent::MouseButtonPress &&
(mevent->modifiers() & Qt::ControlModifier)) {
return QItemSelectionModel::NoUpdate;
}
if (event->type() == QEvent::MouseButtonRelease &&
(mevent->modifiers() & Qt::ControlModifier)) {
return QItemSelectionModel::Toggle;
}
}
return QAbstractItemView::selectionCommand(index, event);
}
void TimelineFramesView::slotSelectionChanged()
{
int minColumn = std::numeric_limits::max();
int maxColumn = std::numeric_limits::min();
foreach (const QModelIndex &idx, selectedIndexes()) {
if (idx.column() > maxColumn) {
maxColumn = idx.column();
}
if (idx.column() < minColumn) {
minColumn = idx.column();
}
}
KisTimeRange range;
if (maxColumn > minColumn) {
range = KisTimeRange(minColumn, maxColumn - minColumn + 1);
}
m_d->model->setPlaybackRange(range);
}
void TimelineFramesView::slotReselectCurrentIndex()
{
QModelIndex index = currentIndex();
currentChanged(index, index);
}
void TimelineFramesView::slotEnsureRowVisible(int row)
{
QModelIndex index = currentIndex();
if (!index.isValid() || row < 0) return;
index = m_d->model->index(row, index.column());
scrollTo(index);
}
void TimelineFramesView::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
if (m_d->model->isPlaybackActive()) return;
int selectedColumn = -1;
for (int j = topLeft.column(); j <= bottomRight.column(); j++) {
QVariant value = m_d->model->data(
m_d->model->index(topLeft.row(), j),
TimelineFramesModel::ActiveFrameRole);
if (value.isValid() && value.toBool()) {
selectedColumn = j;
break;
}
}
QModelIndex index = currentIndex();
if (!index.isValid() && selectedColumn < 0) {
return;
}
if (selectedColumn == -1) {
selectedColumn = index.column();
}
if (selectedColumn != index.column() && !m_d->dragInProgress) {
int row= index.isValid() ? index.row() : 0;
selectionModel()->setCurrentIndex(m_d->model->index(row, selectedColumn), QItemSelectionModel::ClearAndSelect);
}
+
}
void TimelineFramesView::slotHeaderDataChanged(Qt::Orientation orientation, int first, int last)
{
Q_UNUSED(first);
Q_UNUSED(last);
if (orientation == Qt::Horizontal) {
const int newFps = m_d->model->headerData(0, Qt::Horizontal, TimelineFramesModel::FramesPerSecondRole).toInt();
if (newFps != m_d->fps) {
setFramesPerSecond(newFps);
}
}
}
void TimelineFramesView::rowsInserted(const QModelIndex& parent, int start, int end)
{
QTableView::rowsInserted(parent, start, end);
}
inline bool isIndexDragEnabled(QAbstractItemModel *model, const QModelIndex &index) {
return (model->flags(index) & Qt::ItemIsDragEnabled);
}
QStyleOptionViewItem TimelineFramesView::Private::viewOptionsV4() const
{
QStyleOptionViewItem option = q->viewOptions();
option.locale = q->locale();
option.locale.setNumberOptions(QLocale::OmitGroupSeparator);
option.widget = q;
return option;
}
QItemViewPaintPairs TimelineFramesView::Private::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
{
Q_ASSERT(r);
QRect &rect = *r;
const QRect viewportRect = q->viewport()->rect();
QItemViewPaintPairs ret;
for (int i = 0; i < indexes.count(); ++i) {
const QModelIndex &index = indexes.at(i);
const QRect current = q->visualRect(index);
if (current.intersects(viewportRect)) {
ret += qMakePair(current, index);
rect |= current;
}
}
rect &= viewportRect;
return ret;
}
QPixmap TimelineFramesView::Private::renderToPixmap(const QModelIndexList &indexes, QRect *r) const
{
Q_ASSERT(r);
QItemViewPaintPairs paintPairs = draggablePaintPairs(indexes, r);
if (paintPairs.isEmpty())
return QPixmap();
QPixmap pixmap(r->size());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QStyleOptionViewItem option = viewOptionsV4();
option.state |= QStyle::State_Selected;
for (int j = 0; j < paintPairs.count(); ++j) {
option.rect = paintPairs.at(j).first.translated(-r->topLeft());
const QModelIndex ¤t = paintPairs.at(j).second;
//adjustViewOptionsForIndex(&option, current);
q->itemDelegate(current)->paint(&painter, option, current);
}
return pixmap;
}
void TimelineFramesView::startDrag(Qt::DropActions supportedActions)
{
QModelIndexList indexes = selectionModel()->selectedIndexes();
if (!indexes.isEmpty() && m_d->modifiersCatcher->modifierPressed("offset-frame")) {
QVector rows;
int leftmostColumn = std::numeric_limits::max();
Q_FOREACH (const QModelIndex &index, indexes) {
leftmostColumn = qMin(leftmostColumn, index.column());
if (!rows.contains(index.row())) {
rows.append(index.row());
}
}
const int lastColumn = m_d->model->columnCount() - 1;
selectionModel()->clear();
Q_FOREACH (const int row, rows) {
QItemSelection sel(m_d->model->index(row, leftmostColumn), m_d->model->index(row, lastColumn));
selectionModel()->select(sel, QItemSelectionModel::Select);
}
supportedActions = Qt::MoveAction;
{
QModelIndexList indexes = selectedIndexes();
for(int i = indexes.count() - 1 ; i >= 0; --i) {
if (!isIndexDragEnabled(m_d->model, indexes.at(i)))
indexes.removeAt(i);
}
selectionModel()->clear();
if (indexes.count() > 0) {
QMimeData *data = m_d->model->mimeData(indexes);
if (!data)
return;
QRect rect;
QPixmap pixmap = m_d->renderToPixmap(indexes, &rect);
rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
QDrag *drag = new QDrag(this);
drag->setPixmap(pixmap);
drag->setMimeData(data);
drag->setHotSpot(m_d->lastPressedPosition - rect.topLeft());
drag->exec(supportedActions, Qt::MoveAction);
setCurrentIndex(currentIndex());
}
}
} else {
/**
* Workaround for Qt5's bug: if we start a dragging action right during
* Shift-selection, Qt will get crazy. We cannot workaround it easily,
* because we would need to fork mouseMoveEvent() for that (where the
* decision about drag state is done). So we just abort dragging in that
* case.
*
* BUG:373067
*/
if (m_d->lastPressedModifier & Qt::ShiftModifier) {
return;
}
/**
* Workaround for Qt5's bugs:
*
* 1) Qt doesn't treat selection the selection on D&D
* correctly, so we save it in advance and restore
* afterwards.
*
* 2) There is a private variable in QAbstractItemView:
* QAbstractItemView::Private::currentSelectionStartIndex.
* It is initialized *only* when the setCurrentIndex() is called
* explicitly on the view object, not on the selection model.
* Therefore we should explicitly call setCurrentIndex() after
* D&D, even if it already has *correct* value!
*
* 2) We should also call selectionModel()->select()
* explicitly. There are two reasons for it: 1) Qt doesn't
* maintain selection over D&D; 2) when reselecting single
* element after D&D, Qt goes crazy, because it tries to
* read *global* keyboard modifiers. Therefore if we are
* dragging with Shift or Ctrl pressed it'll get crazy. So
* just reset it explicitly.
*/
QModelIndexList selectionBefore = selectionModel()->selectedIndexes();
QModelIndex currentBefore = selectionModel()->currentIndex();
// initialize a global status variable
m_d->dragWasSuccessful = false;
QAbstractItemView::startDrag(supportedActions);
QModelIndex newCurrent;
QPoint selectionOffset;
if (m_d->dragWasSuccessful) {
newCurrent = currentIndex();
selectionOffset = QPoint(newCurrent.column() - currentBefore.column(),
newCurrent.row() - currentBefore.row());
} else {
newCurrent = currentBefore;
selectionOffset = QPoint();
}
setCurrentIndex(newCurrent);
selectionModel()->clearSelection();
Q_FOREACH (const QModelIndex &idx, selectionBefore) {
QModelIndex newIndex =
model()->index(idx.row() + selectionOffset.y(),
idx.column() + selectionOffset.x());
selectionModel()->select(newIndex, QItemSelectionModel::Select);
}
}
}
void TimelineFramesView::dragEnterEvent(QDragEnterEvent *event)
{
m_d->dragInProgress = true;
m_d->model->setScrubState(true);
QTableView::dragEnterEvent(event);
}
void TimelineFramesView::dragMoveEvent(QDragMoveEvent *event)
{
m_d->dragInProgress = true;
m_d->model->setScrubState(true);
QTableView::dragMoveEvent(event);
if (event->isAccepted()) {
QModelIndex index = indexAt(event->pos());
if (!m_d->model->canDropFrameData(event->mimeData(), index)) {
event->ignore();
} else {
selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
}
}
}
void TimelineFramesView::dropEvent(QDropEvent *event)
{
m_d->dragInProgress = false;
m_d->model->setScrubState(false);
if (event->keyboardModifiers() & Qt::ControlModifier) {
event->setDropAction(Qt::CopyAction);
}
QAbstractItemView::dropEvent(event);
m_d->dragWasSuccessful = event->isAccepted();
}
void TimelineFramesView::dragLeaveEvent(QDragLeaveEvent *event)
{
m_d->dragInProgress = false;
m_d->model->setScrubState(false);
QAbstractItemView::dragLeaveEvent(event);
}
void TimelineFramesView::createFrameEditingMenuActions(QMenu *menu, bool addFrameCreationActions)
{
slotUpdateFrameActions();
// calculate if selection range is set. This will determine if the update playback range is available
QSet rows;
int minColumn = 0;
int maxColumn = 0;
calculateSelectionMetrics(minColumn, maxColumn, rows);
bool selectionExists = minColumn != maxColumn;
if (selectionExists) {
KisActionManager::safePopulateMenu(menu, "update_playback_range", m_d->actionMan);
} else {
KisActionManager::safePopulateMenu(menu, "set_start_time", m_d->actionMan);
KisActionManager::safePopulateMenu(menu, "set_end_time", m_d->actionMan);
}
menu->addSeparator();
KisActionManager::safePopulateMenu(menu, "cut_frames_to_clipboard", m_d->actionMan);
KisActionManager::safePopulateMenu(menu, "copy_frames_to_clipboard", m_d->actionMan);
KisActionManager::safePopulateMenu(menu, "paste_frames_from_clipboard", m_d->actionMan);
menu->addSeparator();
+ { // Tween submenu.
+ QMenu *frames = menu->addMenu(i18nc("@item:inmenu", "Tweening"));
+ KisActionManager::safePopulateMenu(frames, "insert_opacity_keyframe", m_d->actionMan);
+ KisActionManager::safePopulateMenu(frames, "remove_opacity_keyframe", m_d->actionMan);
+ }
+
+
{ //Frames submenu.
QMenu *frames = menu->addMenu(i18nc("@item:inmenu", "Keyframes"));
KisActionManager::safePopulateMenu(frames, "insert_keyframe_left", m_d->actionMan);
KisActionManager::safePopulateMenu(frames, "insert_keyframe_right", m_d->actionMan);
frames->addSeparator();
KisActionManager::safePopulateMenu(frames, "insert_multiple_keyframes", m_d->actionMan);
}
{ //Holds submenu.
QMenu *hold = menu->addMenu(i18nc("@item:inmenu", "Hold Frames"));
KisActionManager::safePopulateMenu(hold, "insert_hold_frame", m_d->actionMan);
KisActionManager::safePopulateMenu(hold, "remove_hold_frame", m_d->actionMan);
hold->addSeparator();
KisActionManager::safePopulateMenu(hold, "insert_multiple_hold_frames", m_d->actionMan);
KisActionManager::safePopulateMenu(hold, "remove_multiple_hold_frames", m_d->actionMan);
}
menu->addSeparator();
KisActionManager::safePopulateMenu(menu, "remove_frames", m_d->actionMan);
KisActionManager::safePopulateMenu(menu, "remove_frames_and_pull", m_d->actionMan);
menu->addSeparator();
if (addFrameCreationActions) {
KisActionManager::safePopulateMenu(menu, "add_blank_frame", m_d->actionMan);
KisActionManager::safePopulateMenu(menu, "add_duplicate_frame", m_d->actionMan);
menu->addSeparator();
}
}
void TimelineFramesView::mousePressEvent(QMouseEvent *event)
{
QPersistentModelIndex index = indexAt(event->pos());
if (m_d->modifiersCatcher->modifierPressed("pan-zoom")) {
if (event->button() == Qt::RightButton) {
// TODO: try calculate index under mouse cursor even when
// it is outside any visible row
qreal staticPoint = index.isValid() ? index.column() : currentIndex().column();
m_d->zoomDragButton->beginZoom(event->pos(), staticPoint);
} else if (event->button() == Qt::LeftButton) {
m_d->initialDragPanPos = event->pos();
m_d->initialDragPanValue =
QPoint(horizontalScrollBar()->value(),
verticalScrollBar()->value());
}
event->accept();
} else if (event->button() == Qt::RightButton) {
int numSelectedItems = selectionModel()->selectedIndexes().size();
if (index.isValid() &&
numSelectedItems <= 1 &&
m_d->model->data(index, TimelineFramesModel::FrameEditableRole).toBool()) {
model()->setData(index, true, TimelineFramesModel::ActiveLayerRole);
model()->setData(index, true, TimelineFramesModel::ActiveFrameRole);
setCurrentIndex(index);
if (model()->data(index, TimelineFramesModel::FrameExistsRole).toBool() ||
model()->data(index, TimelineFramesModel::SpecialKeyframeExists).toBool()) {
{
KisSignalsBlocker b(m_d->colorSelector);
QVariant colorLabel = index.data(TimelineFramesModel::FrameColorLabelIndexRole);
int labelIndex = colorLabel.isValid() ? colorLabel.toInt() : 0;
m_d->colorSelector->setCurrentIndex(labelIndex);
}
QMenu menu;
createFrameEditingMenuActions(&menu, false);
menu.addSeparator();
menu.addAction(m_d->colorSelectorAction);
menu.exec(event->globalPos());
} else {
{
KisSignalsBlocker b(m_d->colorSelector);
const int labelIndex = KisImageConfig(true).defaultFrameColorLabel();
m_d->colorSelector->setCurrentIndex(labelIndex);
}
QMenu menu;
createFrameEditingMenuActions(&menu, true);
menu.addSeparator();
menu.addAction(m_d->colorSelectorAction);
menu.exec(event->globalPos());
}
} else if (numSelectedItems > 1) {
int labelIndex = -1;
bool haveFrames = false;
Q_FOREACH(QModelIndex index, selectedIndexes()) {
haveFrames |= index.data(TimelineFramesModel::FrameExistsRole).toBool();
QVariant colorLabel = index.data(TimelineFramesModel::FrameColorLabelIndexRole);
if (colorLabel.isValid()) {
if (labelIndex == -1) {
// First label
labelIndex = colorLabel.toInt();
} else if (labelIndex != colorLabel.toInt()) {
// Mixed colors in selection
labelIndex = -1;
break;
}
}
}
if (haveFrames) {
KisSignalsBlocker b(m_d->multiframeColorSelector);
m_d->multiframeColorSelector->setCurrentIndex(labelIndex);
}
QMenu menu;
createFrameEditingMenuActions(&menu, false);
menu.addSeparator();
KisActionManager::safePopulateMenu(&menu, "mirror_frames", m_d->actionMan);
menu.addSeparator();
menu.addAction(m_d->multiframeColorSelectorAction);
menu.exec(event->globalPos());
}
} else if (event->button() == Qt::MidButton) {
QModelIndex index = model()->buddy(indexAt(event->pos()));
if (index.isValid()) {
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(index);
// The offset of the headers is needed to get the correct position inside the view.
m_d->tip.showTip(this, event->pos() + QPoint(verticalHeader()->width(), horizontalHeader()->height()), option, index);
}
event->accept();
} else {
if (index.isValid()) {
m_d->model->setLastClickedIndex(index);
}
m_d->lastPressedPosition =
QPoint(horizontalOffset(), verticalOffset()) + event->pos();
m_d->lastPressedModifier = event->modifiers();
QAbstractItemView::mousePressEvent(event);
}
}
void TimelineFramesView::mouseMoveEvent(QMouseEvent *e)
{
if (m_d->modifiersCatcher->modifierPressed("pan-zoom")) {
if (e->buttons() & Qt::RightButton) {
m_d->zoomDragButton->continueZoom(e->pos());
} else if (e->buttons() & Qt::LeftButton) {
QPoint diff = e->pos() - m_d->initialDragPanPos;
QPoint offset = QPoint(m_d->initialDragPanValue.x() - diff.x(),
m_d->initialDragPanValue.y() - diff.y());
const int height = m_d->layersHeader->defaultSectionSize();
horizontalScrollBar()->setValue(offset.x());
verticalScrollBar()->setValue(offset.y() / height);
}
e->accept();
} else if (e->buttons() == Qt::MidButton) {
QModelIndex index = model()->buddy(indexAt(e->pos()));
if (index.isValid()) {
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(index);
// The offset of the headers is needed to get the correct position inside the view.
m_d->tip.showTip(this, e->pos() + QPoint(verticalHeader()->width(), horizontalHeader()->height()), option, index);
}
e->accept();
} else {
m_d->model->setScrubState(true);
QTableView::mouseMoveEvent(e);
}
}
void TimelineFramesView::mouseReleaseEvent(QMouseEvent *e)
{
if (m_d->modifiersCatcher->modifierPressed("pan-zoom")) {
e->accept();
} else {
m_d->model->setScrubState(false);
QTableView::mouseReleaseEvent(e);
}
}
void TimelineFramesView::wheelEvent(QWheelEvent *e)
{
QModelIndex index = currentIndex();
int column= -1;
if (index.isValid()) {
column= index.column() + ((e->delta() > 0) ? 1 : -1);
}
if (column >= 0 && !m_d->dragInProgress) {
setCurrentIndex(m_d->model->index(index.row(), column));
}
}
void TimelineFramesView::slotUpdateLayersMenu()
{
QAction *action = 0;
m_d->existingLayersMenu->clear();
QVariant value = model()->headerData(0, Qt::Vertical, TimelineFramesModel::OtherLayersRole);
if (value.isValid()) {
TimelineFramesModel::OtherLayersList list = value.value();
int i = 0;
Q_FOREACH (const TimelineFramesModel::OtherLayer &l, list) {
action = m_d->existingLayersMenu->addAction(l.name);
action->setData(i++);
}
}
}
void TimelineFramesView::slotUpdateFrameActions()
{
if (!m_d->actionMan) return;
const QModelIndexList editableIndexes = calculateSelectionSpan(false, true);
const bool hasEditableFrames = !editableIndexes.isEmpty();
bool hasExistingFrames = false;
Q_FOREACH (const QModelIndex &index, editableIndexes) {
if (model()->data(index, TimelineFramesModel::FrameExistsRole).toBool()) {
hasExistingFrames = true;
break;
}
}
auto enableAction = [this] (const QString &id, bool value) {
KisAction *action = m_d->actionMan->actionByName(id);
KIS_SAFE_ASSERT_RECOVER_RETURN(action);
action->setEnabled(value);
};
enableAction("add_blank_frame", hasEditableFrames);
enableAction("add_duplicate_frame", hasEditableFrames);
enableAction("insert_keyframe_left", hasEditableFrames);
enableAction("insert_keyframe_right", hasEditableFrames);
enableAction("insert_multiple_keyframes", hasEditableFrames);
enableAction("remove_frames", hasEditableFrames && hasExistingFrames);
enableAction("remove_frames_and_pull", hasEditableFrames);
enableAction("insert_hold_frame", hasEditableFrames);
enableAction("insert_multiple_hold_frames", hasEditableFrames);
enableAction("remove_hold_frame", hasEditableFrames);
enableAction("remove_multiple_hold_frames", hasEditableFrames);
enableAction("mirror_frames", hasEditableFrames && editableIndexes.size() > 1);
enableAction("copy_frames_to_clipboard", true);
enableAction("cut_frames_to_clipboard", hasEditableFrames);
+ enableAction("insert_opacity_keyframe", hasEditableFrames);
+ enableAction("remove_opacity_keyframe", hasEditableFrames);
+
QClipboard *cp = QApplication::clipboard();
const QMimeData *data = cp->mimeData();
- enableAction("paste_frames_from_clipboard", data && data->hasFormat("application/x-krita-frame"));
//TODO: update column actions!
}
void TimelineFramesView::slotSetStartTimeToCurrentPosition()
{
m_d->model->setFullClipRangeStart(this->currentIndex().column());
}
void TimelineFramesView::slotSetEndTimeToCurrentPosition()
{
m_d->model->setFullClipRangeEnd(this->currentIndex().column());
}
void TimelineFramesView::slotUpdatePlackbackRange()
{
QSet rows;
int minColumn = 0;
int maxColumn = 0;
calculateSelectionMetrics(minColumn, maxColumn, rows);
m_d->model->setFullClipRangeStart(minColumn);
m_d->model->setFullClipRangeEnd(maxColumn);
}
void TimelineFramesView::slotLayerContextMenuRequested(const QPoint &globalPos)
{
m_d->layerEditingMenu->exec(globalPos);
}
void TimelineFramesView::slotAddNewLayer()
{
QModelIndex index = currentIndex();
const int newRow = index.isValid() ? index.row() : 0;
model()->insertRow(newRow);
}
void TimelineFramesView::slotAddExistingLayer(QAction *action)
{
QVariant value = action->data();
if (value.isValid()) {
QModelIndex index = currentIndex();
const int newRow = index.isValid() ? index.row() + 1 : 0;
m_d->model->insertOtherLayer(value.toInt(), newRow);
}
}
void TimelineFramesView::slotRemoveLayer()
{
QModelIndex index = currentIndex();
if (!index.isValid()) return;
model()->removeRow(index.row());
}
void TimelineFramesView::slotAddBlankFrame()
{
QModelIndex index = currentIndex();
if (!index.isValid() ||
!m_d->model->data(index, TimelineFramesModel::FrameEditableRole).toBool()) {
return;
}
m_d->model->createFrame(index);
}
void TimelineFramesView::slotAddDuplicateFrame()
{
QModelIndex index = currentIndex();
if (!index.isValid() ||
!m_d->model->data(index, TimelineFramesModel::FrameEditableRole).toBool()) {
return;
}
m_d->model->copyFrame(index);
}
void TimelineFramesView::calculateSelectionMetrics(int &minColumn, int &maxColumn, QSet &rows) const
{
minColumn = std::numeric_limits::max();
maxColumn = std::numeric_limits::min();
Q_FOREACH (const QModelIndex &index, selectionModel()->selectedIndexes()) {
if (!m_d->model->data(index, TimelineFramesModel::FrameEditableRole).toBool()) continue;
rows.insert(index.row());
minColumn = qMin(minColumn, index.column());
maxColumn = qMax(maxColumn, index.column());
}
}
void TimelineFramesView::insertKeyframes(int count, int timing, TimelineDirection direction, bool entireColumn)
{
QSet rows;
int minColumn = 0, maxColumn = 0;
calculateSelectionMetrics(minColumn, maxColumn, rows);
if (count <= 0) { //Negative count? Use number of selected frames.
count = qMax(1, maxColumn - minColumn + 1);
}
const int insertionColumn =
direction == TimelineDirection::RIGHT ?
maxColumn + 1 : minColumn;
if (entireColumn) {
rows.clear();
for (int i = 0; i < m_d->model->rowCount(); i++) {
if (!m_d->model->data(m_d->model->index(i, insertionColumn), TimelineFramesModel::FrameEditableRole).toBool()) continue;
rows.insert(i);
}
}
if (!rows.isEmpty()) {
m_d->model->insertFrames(insertionColumn, rows.toList(), count, timing);
}
}
void TimelineFramesView::insertMultipleKeyframes(bool entireColumn)
{
int count, timing;
TimelineDirection direction;
if (m_d->insertKeyframeDialog->promptUserSettings(count, timing, direction)) {
insertKeyframes(count, timing, direction, entireColumn);
}
}
QModelIndexList TimelineFramesView::calculateSelectionSpan(bool entireColumn, bool editableOnly) const
{
QModelIndexList indexes;
if (entireColumn) {
QSet rows;
int minColumn = 0;
int maxColumn = 0;
calculateSelectionMetrics(minColumn, maxColumn, rows);
rows.clear();
for (int i = 0; i < m_d->model->rowCount(); i++) {
if (editableOnly &&
!m_d->model->data(m_d->model->index(i, minColumn), TimelineFramesModel::FrameEditableRole).toBool()) continue;
for (int column = minColumn; column <= maxColumn; column++) {
indexes << m_d->model->index(i, column);
}
}
} else {
Q_FOREACH (const QModelIndex &index, selectionModel()->selectedIndexes()) {
if (!editableOnly || m_d->model->data(index, TimelineFramesModel::FrameEditableRole).toBool()) {
indexes << index;
}
}
}
return indexes;
}
void TimelineFramesView::slotRemoveSelectedFrames(bool entireColumn, bool pull)
{
const QModelIndexList selectedIndices = calculateSelectionSpan(entireColumn);
if (!selectedIndices.isEmpty()) {
if (pull) {
m_d->model->removeFramesAndOffset(selectedIndices);
} else {
m_d->model->removeFrames(selectedIndices);
}
}
}
void TimelineFramesView::insertOrRemoveHoldFrames(int count, bool entireColumn)
{
QModelIndexList indexes;
if (!entireColumn) {
Q_FOREACH (const QModelIndex &index, selectionModel()->selectedIndexes()) {
if (m_d->model->data(index, TimelineFramesModel::FrameEditableRole).toBool()) {
indexes << index;
}
}
} else {
const int column = selectionModel()->currentIndex().column();
for (int i = 0; i < m_d->model->rowCount(); i++) {
const QModelIndex index = m_d->model->index(i, column);
if (m_d->model->data(index, TimelineFramesModel::FrameEditableRole).toBool()) {
indexes << index;
}
}
}
if (!indexes.isEmpty()) {
// add extra columns to the end of the timeline if we are adding hold frames
// they will be truncated if we don't do this
if (count > 0) {
// Scan all the layers and find out what layer has the most keyframes
// only keep a reference of layer that has the most keyframes
int keyframesInLayerNode = 0;
Q_FOREACH (const QModelIndex &index, indexes) {
KisNodeSP layerNode = m_d->model->nodeAt(index);
KisKeyframeChannel *channel = layerNode->getKeyframeChannel(KisKeyframeChannel::Content.id());
if (!channel) continue;
if (keyframesInLayerNode < channel->allKeyframeIds().count()) {
keyframesInLayerNode = channel->allKeyframeIds().count();
}
}
m_d->model->setLastVisibleFrame(m_d->model->columnCount() + count*keyframesInLayerNode);
}
m_d->model->insertHoldFrames(indexes, count);
// bulk adding frames can add too many
// trim timeline to clean up extra frames that might have been added
slotUpdateInfiniteFramesCount();
}
}
void TimelineFramesView::insertOrRemoveMultipleHoldFrames(bool insertion, bool entireColumn)
{
bool ok = false;
const int count = QInputDialog::getInt(this,
i18nc("@title:window", "Insert or Remove Hold Frames"),
i18nc("@label:spinbox", "Enter number of frames"),
insertion ?
m_d->insertKeyframeDialog->defaultTimingOfAddedFrames() :
m_d->insertKeyframeDialog->defaultNumberOfHoldFramesToRemove(),
1, 10000, 1, &ok);
if (ok) {
if (insertion) {
m_d->insertKeyframeDialog->setDefaultTimingOfAddedFrames(count);
insertOrRemoveHoldFrames(count, entireColumn);
} else {
m_d->insertKeyframeDialog->setDefaultNumberOfHoldFramesToRemove(count);
insertOrRemoveHoldFrames(-count, entireColumn);
}
}
}
void TimelineFramesView::slotMirrorFrames(bool entireColumn)
{
const QModelIndexList indexes = calculateSelectionSpan(entireColumn);
if (!indexes.isEmpty()) {
m_d->model->mirrorFrames(indexes);
}
}
void TimelineFramesView::cutCopyImpl(bool entireColumn, bool copy)
{
const QModelIndexList selectedIndices = calculateSelectionSpan(entireColumn, !copy);
if (selectedIndices.isEmpty()) return;
int minColumn = std::numeric_limits::max();
int minRow = std::numeric_limits::max();
Q_FOREACH (const QModelIndex &index, selectedIndices) {
minRow = qMin(minRow, index.row());
minColumn = qMin(minColumn, index.column());
}
const QModelIndex baseIndex = m_d->model->index(minRow, minColumn);
QMimeData *data = m_d->model->mimeDataExtended(selectedIndices,
baseIndex,
copy ?
TimelineFramesModel::CopyFramesPolicy :
TimelineFramesModel::MoveFramesPolicy);
if (data) {
QClipboard *cb = QApplication::clipboard();
cb->setMimeData(data);
}
}
void TimelineFramesView::slotPasteFrames(bool entireColumn)
{
const QModelIndex currentIndex =
!entireColumn ? this->currentIndex() : m_d->model->index(0, this->currentIndex().column());
if (!currentIndex.isValid()) return;
QClipboard *cb = QApplication::clipboard();
const QMimeData *data = cb->mimeData();
if (data && data->hasFormat("application/x-krita-frame")) {
bool dataMoved = false;
bool result = m_d->model->dropMimeDataExtended(data, Qt::MoveAction, currentIndex, &dataMoved);
if (result && dataMoved) {
cb->clear();
}
}
}
bool TimelineFramesView::viewportEvent(QEvent *event)
{
if (event->type() == QEvent::ToolTip && model()) {
QHelpEvent *he = static_cast(event);
QModelIndex index = model()->buddy(indexAt(he->pos()));
if (index.isValid()) {
QStyleOptionViewItem option = viewOptions();
option.rect = visualRect(index);
// The offset of the headers is needed to get the correct position inside the view.
m_d->tip.showTip(this, he->pos() + QPoint(verticalHeader()->width(), horizontalHeader()->height()), option, index);
return true;
}
}
return QTableView::viewportEvent(event);
}
diff --git a/plugins/dockers/animation/timeline_ruler_header.cpp b/plugins/dockers/animation/timeline_ruler_header.cpp
index c62e737bda..481149a618 100644
--- a/plugins/dockers/animation/timeline_ruler_header.cpp
+++ b/plugins/dockers/animation/timeline_ruler_header.cpp
@@ -1,542 +1,547 @@
/*
* Copyright (c) 2015 Dmitry Kazakov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "timeline_ruler_header.h"
#include
#include
#include
#include
#include
#include
#include "kis_time_based_item_model.h"
#include "timeline_color_scheme.h"
#include "kis_action.h"
#include "kis_debug.h"
struct TimelineRulerHeader::Private
{
Private() : fps(12), lastPressSectionIndex(-1) {}
int fps;
KisTimeBasedItemModel *model;
int lastPressSectionIndex;
int calcSpanWidth(const int sectionWidth);
QModelIndexList prepareFramesSlab(int startCol, int endCol);
KisActionManager* actionMan = 0;
};
TimelineRulerHeader::TimelineRulerHeader(QWidget *parent)
: QHeaderView(Qt::Horizontal, parent),
m_d(new Private)
{
setSectionResizeMode(QHeaderView::Fixed);
setDefaultSectionSize(18);
setMinimumSectionSize(8);
}
TimelineRulerHeader::~TimelineRulerHeader()
{
}
void TimelineRulerHeader::setActionManager(KisActionManager *actionManager)
{
m_d->actionMan = actionManager;
if (actionManager) {
KisAction *action;
action = actionManager->createAction("insert_column_left");
connect(action, SIGNAL(triggered()), SIGNAL(sigInsertColumnLeft()));
action = actionManager->createAction("insert_column_right");
connect(action, SIGNAL(triggered()), SIGNAL(sigInsertColumnRight()));
action = actionManager->createAction("insert_multiple_columns");
connect(action, SIGNAL(triggered()), SIGNAL(sigInsertMultipleColumns()));
action = actionManager->createAction("remove_columns_and_pull");
connect(action, SIGNAL(triggered()), SIGNAL(sigRemoveColumnsAndShift()));
action = actionManager->createAction("remove_columns");
connect(action, SIGNAL(triggered()), SIGNAL(sigRemoveColumns()));
action = actionManager->createAction("insert_hold_column");
connect(action, SIGNAL(triggered()), SIGNAL(sigInsertHoldColumns()));
action = actionManager->createAction("insert_multiple_hold_columns");
connect(action, SIGNAL(triggered()), SIGNAL(sigInsertHoldColumnsCustom()));
action = actionManager->createAction("remove_hold_column");
connect(action, SIGNAL(triggered()), SIGNAL(sigRemoveHoldColumns()));
action = actionManager->createAction("remove_multiple_hold_columns");
connect(action, SIGNAL(triggered()), SIGNAL(sigRemoveHoldColumnsCustom()));
action = actionManager->createAction("mirror_columns");
connect(action, SIGNAL(triggered()), SIGNAL(sigMirrorColumns()));
action = actionManager->createAction("copy_columns_to_clipboard");
connect(action, SIGNAL(triggered()), SIGNAL(sigCopyColumns()));
action = actionManager->createAction("cut_columns_to_clipboard");
connect(action, SIGNAL(triggered()), SIGNAL(sigCutColumns()));
action = actionManager->createAction("paste_columns_from_clipboard");
connect(action, SIGNAL(triggered()), SIGNAL(sigPasteColumns()));
}
}
void TimelineRulerHeader::paintEvent(QPaintEvent *e)
{
QHeaderView::paintEvent(e);
// Copied from Qt 4.8...
if (count() == 0)
return;
QPainter painter(viewport());
const QPoint offset = dirtyRegionOffset();
QRect translatedEventRect = e->rect();
translatedEventRect.translate(offset);
int start = -1;
int end = -1;
if (orientation() == Qt::Horizontal) {
start = visualIndexAt(translatedEventRect.left());
end = visualIndexAt(translatedEventRect.right());
} else {
start = visualIndexAt(translatedEventRect.top());
end = visualIndexAt(translatedEventRect.bottom());
}
const bool reverseImpl = orientation() == Qt::Horizontal && isRightToLeft();
if (reverseImpl) {
start = (start == -1 ? count() - 1 : start);
end = (end == -1 ? 0 : end);
} else {
start = (start == -1 ? 0 : start);
end = (end == -1 ? count() - 1 : end);
}
int tmp = start;
start = qMin(start, end);
end = qMax(tmp, end);
///////////////////////////////////////////////////
/// Krita specific code. We should update in spans!
const int spanStart = start - start % m_d->fps;
const int spanEnd = end - end % m_d->fps + m_d->fps - 1;
start = spanStart;
end = qMin(count() - 1, spanEnd);
/// End of Krita specific code
///////////////////////////////////////////////////
QRect currentSectionRect;
int logical;
const int width = viewport()->width();
const int height = viewport()->height();
+
for (int i = start; i <= end; ++i) {
// DK: cannot copy-paste easily...
// if (d->isVisualIndexHidden(i))
// continue;
painter.save();
logical = logicalIndex(i);
if (orientation() == Qt::Horizontal) {
currentSectionRect.setRect(sectionViewportPosition(logical), 0, sectionSize(logical), height);
} else {
currentSectionRect.setRect(0, sectionViewportPosition(logical), width, sectionSize(logical));
}
currentSectionRect.translate(offset);
QVariant variant = model()->headerData(logical, orientation(),
Qt::FontRole);
if (variant.isValid() && variant.canConvert()) {
QFont sectionFont = qvariant_cast(variant);
painter.setFont(sectionFont);
}
paintSection1(&painter, currentSectionRect, logical);
painter.restore();
}
}
void TimelineRulerHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
// Base paint event should paint nothing in the sections area
Q_UNUSED(painter);
Q_UNUSED(rect);
Q_UNUSED(logicalIndex);
}
void TimelineRulerHeader::paintSpan(QPainter *painter, int userFrameId,
const QRect &spanRect,
bool isIntegralLine,
bool isPrevIntegralLine,
QStyle *style,
const QPalette &palette,
const QPen &gridPen) const
{
painter->fillRect(spanRect, palette.brush(QPalette::Button));
int safeRight = spanRect.right();
QPen oldPen = painter->pen();
painter->setPen(gridPen);
int adjustedTop = spanRect.top() + (!isIntegralLine ? spanRect.height() / 2 : 0);
painter->drawLine(safeRight, adjustedTop, safeRight, spanRect.bottom());
if (isPrevIntegralLine) {
painter->drawLine(spanRect.left() + 1, spanRect.top(), spanRect.left() + 1, spanRect.bottom());
}
painter->setPen(oldPen);
QString frameIdText = QString::number(userFrameId);
QRect textRect(spanRect.topLeft() + QPoint(2, 0), QSize(spanRect.width() - 2, spanRect.height()));
QStyleOptionHeader opt;
initStyleOption(&opt);
QStyle::State state = QStyle::State_None;
if (isEnabled())
state |= QStyle::State_Enabled;
if (window()->isActiveWindow())
state |= QStyle::State_Active;
opt.state |= state;
opt.selectedPosition = QStyleOptionHeader::NotAdjacent;
opt.textAlignment = Qt::AlignLeft | Qt::AlignTop;
opt.rect = textRect;
opt.text = frameIdText;
style->drawControl(QStyle::CE_HeaderLabel, &opt, painter, this);
}
int TimelineRulerHeader::Private::calcSpanWidth(const int sectionWidth) {
const int minWidth = 36;
int spanWidth = this->fps;
while (spanWidth * sectionWidth < minWidth) {
spanWidth *= 2;
}
bool splitHappened = false;
do {
splitHappened = false;
if (!(spanWidth & 0x1) &&
spanWidth * sectionWidth / 2 > minWidth) {
spanWidth /= 2;
splitHappened = true;
} else if (!(spanWidth % 3) &&
spanWidth * sectionWidth / 3 > minWidth) {
spanWidth /= 3;
splitHappened = true;
} else if (!(spanWidth % 5) &&
spanWidth * sectionWidth / 5 > minWidth) {
spanWidth /= 5;
splitHappened = true;
}
} while (splitHappened);
if (sectionWidth > minWidth) {
spanWidth = 1;
}
return spanWidth;
}
void TimelineRulerHeader::paintSection1(QPainter *painter, const QRect &rect, int logicalIndex) const
-{
+{
+
if (!rect.isValid())
return;
QFontMetrics metrics(this->font());
const int textHeight = metrics.height();
QPoint p1 = rect.topLeft() + QPoint(0, textHeight);
QPoint p2 = rect.topRight() + QPoint(0, textHeight);
QRect frameRect = QRect(p1, QSize(rect.width(), rect.height() - textHeight));
const int width = rect.width();
int spanWidth = m_d->calcSpanWidth(width);
const int internalIndex = logicalIndex % spanWidth;
const int userFrameId = logicalIndex;
const int spanEnd = qMin(count(), logicalIndex + spanWidth);
QRect spanRect(rect.topLeft(), QSize(width * (spanEnd - logicalIndex), textHeight));
QStyleOptionViewItem option = viewOptions();
const int gridHint = style()->styleHint(QStyle::SH_Table_GridLineColor, &option, this);
const QColor gridColor = static_cast(gridHint);
const QPen gridPen = QPen(gridColor);
if (!internalIndex) {
bool isIntegralLine = (logicalIndex + spanWidth) % m_d->fps == 0;
bool isPrevIntegralLine = logicalIndex % m_d->fps == 0;
paintSpan(painter, userFrameId, spanRect, isIntegralLine, isPrevIntegralLine, style(), palette(), gridPen);
}
{
QBrush fillColor = TimelineColorScheme::instance()->headerEmpty();
QVariant activeValue = model()->headerData(logicalIndex, orientation(),
KisTimeBasedItemModel::ActiveFrameRole);
QVariant cachedValue = model()->headerData(logicalIndex, orientation(),
KisTimeBasedItemModel::FrameCachedRole);
if (activeValue.isValid() && activeValue.toBool()) {
fillColor = TimelineColorScheme::instance()->headerActive();
} else if (cachedValue.isValid() && cachedValue.toBool()) {
fillColor = TimelineColorScheme::instance()->headerCachedFrame();
}
painter->fillRect(frameRect, fillColor);
QVector lines;
lines << QLine(p1, p2);
lines << QLine(frameRect.topRight(), frameRect.bottomRight());
lines << QLine(frameRect.bottomLeft(), frameRect.bottomRight());
QPen oldPen = painter->pen();
painter->setPen(gridPen);
painter->drawLines(lines);
painter->setPen(oldPen);
}
}
void TimelineRulerHeader::changeEvent(QEvent *event)
{
Q_UNUSED(event);
updateMinimumSize();
}
void TimelineRulerHeader::setFramePerSecond(int fps)
{
m_d->fps = fps;
update();
}
bool TimelineRulerHeader::setZoom(qreal zoom)
{
const int minSectionSize = 4;
const int unitSectionSize = 18;
int newSectionSize = zoom * unitSectionSize;
if (newSectionSize < minSectionSize) {
newSectionSize = minSectionSize;
zoom = qreal(newSectionSize) / unitSectionSize;
}
if (newSectionSize != defaultSectionSize()) {
setDefaultSectionSize(newSectionSize);
return true;
}
return false;
}
void TimelineRulerHeader::updateMinimumSize()
{
QFontMetrics metrics(this->font());
const int textHeight = metrics.height();
setMinimumSize(0, 1.5 * textHeight);
}
void TimelineRulerHeader::setModel(QAbstractItemModel *model)
{
KisTimeBasedItemModel *framesModel = qobject_cast(model);
m_d->model = framesModel;
QHeaderView::setModel(model);
}
int getColumnCount(const QModelIndexList &indexes, int *leftmostCol, int *rightmostCol)
{
QVector columns;
int leftmost = std::numeric_limits::max();
int rightmost = std::numeric_limits::min();
Q_FOREACH (const QModelIndex &index, indexes) {
leftmost = qMin(leftmost, index.column());
rightmost = qMax(rightmost, index.column());
if (!columns.contains(index.column())) {
columns.append(index.column());
}
}
if (leftmostCol) *leftmostCol = leftmost;
if (rightmostCol) *rightmostCol = rightmost;
return columns.size();
}
void TimelineRulerHeader::mousePressEvent(QMouseEvent *e)
{
int logical = logicalIndexAt(e->pos());
if (logical != -1) {
QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
int numSelectedColumns = getColumnCount(selectedIndexes, 0, 0);
if (e->button() == Qt::RightButton) {
if (numSelectedColumns <= 1) {
model()->setHeaderData(logical, orientation(), true, KisTimeBasedItemModel::ActiveFrameRole);
}
/* Fix for safe-assert involving kis_animation_curve_docker.
* There should probably be a more elagant way for dealing
* with reused timeline_ruler_header instances in other
* timeline views instead of simply animation_frame_view.
*
* This works for now though... */
if(!m_d->actionMan){
return;
}
QMenu menu;
KisActionManager::safePopulateMenu(&menu, "cut_columns_to_clipboard", m_d->actionMan);
KisActionManager::safePopulateMenu(&menu, "copy_columns_to_clipboard", m_d->actionMan);
KisActionManager::safePopulateMenu(&menu, "paste_columns_from_clipboard", m_d->actionMan);
menu.addSeparator();
{ //Frame Columns Submenu
QMenu *frames = menu.addMenu(i18nc("@item:inmenu", "Keyframe Columns"));
KisActionManager::safePopulateMenu(frames, "insert_column_left", m_d->actionMan);
KisActionManager::safePopulateMenu(frames, "insert_column_right", m_d->actionMan);
frames->addSeparator();
KisActionManager::safePopulateMenu(frames, "insert_multiple_columns", m_d->actionMan);
}
{ //Hold Columns Submenu
QMenu *hold = menu.addMenu(i18nc("@item:inmenu", "Hold Frame Columns"));
KisActionManager::safePopulateMenu(hold, "insert_hold_column", m_d->actionMan);
KisActionManager::safePopulateMenu(hold, "remove_hold_column", m_d->actionMan);
hold->addSeparator();
KisActionManager::safePopulateMenu(hold, "insert_multiple_hold_columns", m_d->actionMan);
KisActionManager::safePopulateMenu(hold, "remove_multiple_hold_columns", m_d->actionMan);
}
menu.addSeparator();
KisActionManager::safePopulateMenu(&menu, "remove_columns", m_d->actionMan);
KisActionManager::safePopulateMenu(&menu, "remove_columns_and_pull", m_d->actionMan);
if (numSelectedColumns > 1) {
menu.addSeparator();
KisActionManager::safePopulateMenu(&menu, "mirror_columns", m_d->actionMan);
}
menu.exec(e->globalPos());
return;
- } else if (e->button() == Qt::LeftButton) {
+ } else if (e->button() == Qt::LeftButton) {
m_d->lastPressSectionIndex = logical;
model()->setHeaderData(logical, orientation(), true, KisTimeBasedItemModel::ActiveFrameRole);
}
}
QHeaderView::mousePressEvent(e);
}
void TimelineRulerHeader::mouseMoveEvent(QMouseEvent *e)
{
int logical = logicalIndexAt(e->pos());
if (logical != -1) {
+
if (e->buttons() & Qt::LeftButton) {
+
m_d->model->setScrubState(true);
model()->setHeaderData(logical, orientation(), true, KisTimeBasedItemModel::ActiveFrameRole);
if (m_d->lastPressSectionIndex >= 0 &&
logical != m_d->lastPressSectionIndex &&
e->modifiers() & Qt::ShiftModifier) {
const int minCol = qMin(m_d->lastPressSectionIndex, logical);
const int maxCol = qMax(m_d->lastPressSectionIndex, logical);
QItemSelection sel(m_d->model->index(0, minCol), m_d->model->index(0, maxCol));
selectionModel()->select(sel,
QItemSelectionModel::Columns |
QItemSelectionModel::SelectCurrent);
}
}
+
}
QHeaderView::mouseMoveEvent(e);
}
void TimelineRulerHeader::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
m_d->model->setScrubState(false);
}
QHeaderView::mouseReleaseEvent(e);
}
QModelIndexList TimelineRulerHeader::Private::prepareFramesSlab(int startCol, int endCol)
{
QModelIndexList frames;
const int numRows = model->rowCount();
for (int i = 0; i < numRows; i++) {
for (int j = startCol; j <= endCol; j++) {
QModelIndex index = model->index(i, j);
const bool exists = model->data(index, KisTimeBasedItemModel::FrameExistsRole).toBool();
if (exists) {
frames << index;
}
}
}
return frames;
}
diff --git a/plugins/dockers/animation/timeline_ruler_header.h b/plugins/dockers/animation/timeline_ruler_header.h
index a99baf516b..8712b9562d 100644
--- a/plugins/dockers/animation/timeline_ruler_header.h
+++ b/plugins/dockers/animation/timeline_ruler_header.h
@@ -1,87 +1,91 @@
/*
* Copyright (c) 2015 Dmitry Kazakov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TIMELINE_RULER_HEADER_H
#define TIMELINE_RULER_HEADER_H
#include
#include
#include "kis_action_manager.h"
class QPaintEvent;
class TimelineRulerHeader : public QHeaderView
{
Q_OBJECT
public:
TimelineRulerHeader(QWidget *parent = 0);
~TimelineRulerHeader() override;
void setFramePerSecond(int fps);
bool setZoom(qreal zoomLevel);
void setModel(QAbstractItemModel *model) override;
void setActionManager(KisActionManager *actionManager);
+ void mouseMoveEvent(QMouseEvent *e) override;
+
protected:
void mousePressEvent(QMouseEvent *e) override;
- void mouseMoveEvent(QMouseEvent *e) override;
+
void mouseReleaseEvent(QMouseEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override;
void paintSection1(QPainter *painter, const QRect &rect, int logicalIndex) const;
void changeEvent(QEvent *event) override;
private:
void updateMinimumSize();
void paintSpan(QPainter *painter, int userFrameId,
const QRect &spanRect,
bool isIntegralLine,
bool isPrevIntegralLine,
QStyle *style,
const QPalette &palette,
const QPen &gridPen) const;
Q_SIGNALS:
void sigInsertColumnLeft();
void sigInsertColumnRight();
void sigInsertMultipleColumns();
void sigRemoveColumns();
void sigRemoveColumnsAndShift();
void sigInsertHoldColumns();
void sigRemoveHoldColumns();
void sigInsertHoldColumnsCustom();
void sigRemoveHoldColumnsCustom();
void sigMirrorColumns();
void sigCutColumns();
void sigCopyColumns();
void sigPasteColumns();
+
+
private:
struct Private;
const QScopedPointer m_d;
};
#endif // TIMELINE_RULER_HEADER_H
diff --git a/plugins/dockers/layerdocker/LayerBox.cpp b/plugins/dockers/layerdocker/LayerBox.cpp
index aebf3caca7..65dbc20113 100644
--- a/plugins/dockers/layerdocker/LayerBox.cpp
+++ b/plugins/dockers/layerdocker/LayerBox.cpp
@@ -1,1101 +1,1100 @@
/*
* LayerBox.cc - part of Krita aka Krayon aka KimageShop
*
* Copyright (c) 2002 Patrick Julien
* Copyright (C) 2006 Gábor Lehel
* Copyright (C) 2007 Thomas Zander
* Copyright (C) 2007 Boudewijn Rempt
* Copyright (c) 2011 José Luis Vergara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "LayerBox.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "kis_action_manager.h"
#include "widgets/kis_cmb_composite.h"
#include "widgets/kis_slider_spin_box.h"
#include "KisViewManager.h"
#include "kis_node_manager.h"
#include "kis_node_model.h"
#include "canvas/kis_canvas2.h"
#include "kis_dummies_facade_base.h"
#include "kis_shape_controller.h"
#include "kis_selection_mask.h"
#include "kis_config.h"
#include "KisView.h"
#include "krita_utils.h"
#include "kis_color_label_selector_widget.h"
#include "kis_signals_blocker.h"
#include "kis_color_filter_combo.h"
#include "kis_node_filter_proxy_model.h"
#include "kis_selection.h"
#include "kis_processing_applicator.h"
#include "commands/kis_set_global_selection_command.h"
#include "KisSelectionActionsAdapter.h"
#include "kis_layer_utils.h"
#include "ui_WdgLayerBox.h"
#include "NodeView.h"
#include "SyncButtonAndAction.h"
class LayerBoxStyle : public QProxyStyle
{
public:
LayerBoxStyle(QStyle *baseStyle = 0) : QProxyStyle(baseStyle) {}
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
if (element == QStyle::PE_IndicatorItemViewItemDrop)
{
QColor color(widget->palette().color(QPalette::Highlight).lighter());
if (option->rect.height() == 0) {
QBrush brush(color);
QRect r(option->rect);
r.setTop(r.top() - 2);
r.setBottom(r.bottom() + 2);
painter->fillRect(r, brush);
} else {
color.setAlpha(200);
QBrush brush(color);
painter->fillRect(option->rect, brush);
}
}
else
{
QProxyStyle::drawPrimitive(element, option, painter, widget);
}
}
};
inline void LayerBox::connectActionToButton(KisViewManager* viewManager, QAbstractButton *button, const QString &id)
{
if (!viewManager || !button) return;
KisAction *action = viewManager->actionManager()->actionByName(id);
if (!action) return;
connect(button, SIGNAL(clicked()), action, SLOT(trigger()));
connect(action, SIGNAL(sigEnableSlaves(bool)), button, SLOT(setEnabled(bool)));
connect(viewManager->mainWindow(), SIGNAL(themeChanged()), this, SLOT(slotUpdateIcons()));
}
inline void LayerBox::addActionToMenu(QMenu *menu, const QString &id)
{
if (m_canvas) {
menu->addAction(m_canvas->viewManager()->actionManager()->actionByName(id));
}
}
LayerBox::LayerBox()
: QDockWidget(i18n("Layers"))
, m_canvas(0)
, m_wdgLayerBox(new Ui_WdgLayerBox)
, m_thumbnailCompressor(500, KisSignalCompressor::FIRST_INACTIVE)
, m_colorLabelCompressor(900, KisSignalCompressor::FIRST_INACTIVE)
, m_thumbnailSizeCompressor(100, KisSignalCompressor::FIRST_INACTIVE)
{
KisConfig cfg(false);
QWidget* mainWidget = new QWidget(this);
setWidget(mainWidget);
m_opacityDelayTimer.setSingleShot(true);
m_wdgLayerBox->setupUi(mainWidget);
m_wdgLayerBox->listLayers->setStyle(new LayerBoxStyle(m_wdgLayerBox->listLayers->style()));
connect(m_wdgLayerBox->listLayers,
SIGNAL(contextMenuRequested(QPoint,QModelIndex)),
this, SLOT(slotContextMenuRequested(QPoint,QModelIndex)));
connect(m_wdgLayerBox->listLayers,
SIGNAL(collapsed(QModelIndex)), SLOT(slotCollapsed(QModelIndex)));
connect(m_wdgLayerBox->listLayers,
SIGNAL(expanded(QModelIndex)), SLOT(slotExpanded(QModelIndex)));
connect(m_wdgLayerBox->listLayers,
SIGNAL(selectionChanged(QModelIndexList)), SLOT(selectionChanged(QModelIndexList)));
slotUpdateIcons();
m_wdgLayerBox->bnDelete->setIconSize(QSize(22, 22));
m_wdgLayerBox->bnRaise->setIconSize(QSize(22, 22));
m_wdgLayerBox->bnLower->setIconSize(QSize(22, 22));
m_wdgLayerBox->bnProperties->setIconSize(QSize(22, 22));
m_wdgLayerBox->bnDuplicate->setIconSize(QSize(22, 22));
m_wdgLayerBox->bnLower->setEnabled(false);
m_wdgLayerBox->bnRaise->setEnabled(false);
if (cfg.sliderLabels()) {
m_wdgLayerBox->opacityLabel->hide();
m_wdgLayerBox->doubleOpacity->setPrefix(QString("%1: ").arg(i18n("Opacity")));
}
m_wdgLayerBox->doubleOpacity->setRange(0, 100, 0);
m_wdgLayerBox->doubleOpacity->setSuffix("%");
connect(m_wdgLayerBox->doubleOpacity, SIGNAL(valueChanged(qreal)), SLOT(slotOpacitySliderMoved(qreal)));
connect(&m_opacityDelayTimer, SIGNAL(timeout()), SLOT(slotOpacityChanged()));
connect(m_wdgLayerBox->cmbComposite, SIGNAL(activated(int)), SLOT(slotCompositeOpChanged(int)));
m_newLayerMenu = new QMenu(this);
m_wdgLayerBox->bnAdd->setMenu(m_newLayerMenu);
m_wdgLayerBox->bnAdd->setPopupMode(QToolButton::MenuButtonPopup);
m_nodeModel = new KisNodeModel(this);
m_filteringModel = new KisNodeFilterProxyModel(this);
m_filteringModel->setNodeModel(m_nodeModel);
/**
* Connect model updateUI() to enable/disable controls.
* Note: nodeActivated() is connected separately in setImage(), because
* it needs particular order of calls: first the connection to the
* node manager should be called, then updateUI()
*/
connect(m_nodeModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(updateUI()));
connect(m_nodeModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(updateUI()));
connect(m_nodeModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(updateUI()));
connect(m_nodeModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(updateUI()));
connect(m_nodeModel, SIGNAL(modelReset()), SLOT(slotModelReset()));
KisAction *showGlobalSelectionMask = new KisAction(i18n("&Show Global Selection Mask"), this);
showGlobalSelectionMask->setObjectName("show-global-selection-mask");
showGlobalSelectionMask->setActivationFlags(KisAction::ACTIVE_IMAGE);
showGlobalSelectionMask->setToolTip(i18nc("@info:tooltip", "Shows global selection as a usual selection mask in Layers docker"));
showGlobalSelectionMask->setCheckable(true);
connect(showGlobalSelectionMask, SIGNAL(triggered(bool)), SLOT(slotEditGlobalSelection(bool)));
m_actions.append(showGlobalSelectionMask);
showGlobalSelectionMask->setChecked(cfg.showGlobalSelection());
m_colorSelector = new KisColorLabelSelectorWidget(this);
connect(m_colorSelector, SIGNAL(currentIndexChanged(int)), SLOT(slotColorLabelChanged(int)));
m_colorSelectorAction = new QWidgetAction(this);
m_colorSelectorAction->setDefaultWidget(m_colorSelector);
connect(m_nodeModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
&m_colorLabelCompressor, SLOT(start()));
m_wdgLayerBox->listLayers->setModel(m_filteringModel);
// this connection should be done *after* the setModel() call to
// happen later than the internal selection model
connect(m_filteringModel.data(), &KisNodeFilterProxyModel::rowsAboutToBeRemoved,
this, &LayerBox::slotAboutToRemoveRows);
connect(m_wdgLayerBox->cmbFilter, SIGNAL(selectedColorsChanged()), SLOT(updateLayerFiltering()));
setEnabled(false);
connect(&m_thumbnailCompressor, SIGNAL(timeout()), SLOT(updateThumbnail()));
connect(&m_colorLabelCompressor, SIGNAL(timeout()), SLOT(updateAvailableLabels()));
// set up the configure menu for changing thumbnail size
QMenu* configureMenu = new QMenu(this);
configureMenu->setStyleSheet("margin: 6px");
configureMenu->addSection(i18n("Thumbnail Size"));
m_wdgLayerBox->configureLayerDockerToolbar->setMenu(configureMenu);
m_wdgLayerBox->configureLayerDockerToolbar->setIcon(KisIconUtils::loadIcon("configure"));
m_wdgLayerBox->configureLayerDockerToolbar->setPopupMode(QToolButton::InstantPopup);
// add horizontal slider
thumbnailSizeSlider = new QSlider(this);
thumbnailSizeSlider->setOrientation(Qt::Horizontal);
thumbnailSizeSlider->setRange(20, 80);
thumbnailSizeSlider->setValue(cfg.layerThumbnailSize(false)); // grab this from the kritarc
thumbnailSizeSlider->setMinimumHeight(20);
thumbnailSizeSlider->setMinimumWidth(40);
thumbnailSizeSlider->setTickInterval(5);
QWidgetAction *sliderAction= new QWidgetAction(this);
sliderAction->setDefaultWidget(thumbnailSizeSlider);
configureMenu->addAction(sliderAction);
connect(thumbnailSizeSlider, SIGNAL(sliderMoved(int)), &m_thumbnailSizeCompressor, SLOT(start()));
connect(&m_thumbnailSizeCompressor, SIGNAL(timeout()), SLOT(slotUpdateThumbnailIconSize()));
}
LayerBox::~LayerBox()
{
delete m_wdgLayerBox;
}
void expandNodesRecursively(KisNodeSP root, QPointer filteringModel, NodeView *nodeView)
{
if (!root) return;
if (filteringModel.isNull()) return;
if (!nodeView) return;
nodeView->blockSignals(true);
KisNodeSP node = root->firstChild();
while (node) {
QModelIndex idx = filteringModel->indexFromNode(node);
if (idx.isValid()) {
nodeView->setExpanded(idx, !node->collapsed());
}
if (!node->collapsed() && node->childCount() > 0) {
expandNodesRecursively(node, filteringModel, nodeView);
}
node = node->nextSibling();
}
nodeView->blockSignals(false);
}
void LayerBox::slotAddLayerBnClicked()
{
if (m_canvas) {
KisNodeList nodes = m_nodeManager->selectedNodes();
if (nodes.size() == 1) {
KisAction *action = m_canvas->viewManager()->actionManager()->actionByName("add_new_paint_layer");
action->trigger();
} else {
KisAction *action = m_canvas->viewManager()->actionManager()->actionByName("create_quick_group");
action->trigger();
}
}
}
void LayerBox::setViewManager(KisViewManager* kisview)
{
m_nodeManager = kisview->nodeManager();
Q_FOREACH (KisAction *action, m_actions) {
kisview->actionManager()->
addAction(action->objectName(),
action);
}
connect(m_wdgLayerBox->bnAdd, SIGNAL(clicked()), this, SLOT(slotAddLayerBnClicked()));
connectActionToButton(kisview, m_wdgLayerBox->bnDuplicate, "duplicatelayer");
KisActionManager *actionManager = kisview->actionManager();
KisAction *action = actionManager->createAction("RenameCurrentLayer");
Q_ASSERT(action);
connect(action, SIGNAL(triggered()), this, SLOT(slotRenameCurrentNode()));
m_propertiesAction = actionManager->createAction("layer_properties");
Q_ASSERT(m_propertiesAction);
new SyncButtonAndAction(m_propertiesAction, m_wdgLayerBox->bnProperties, this);
connect(m_propertiesAction, SIGNAL(triggered()), this, SLOT(slotPropertiesClicked()));
m_removeAction = actionManager->createAction("remove_layer");
Q_ASSERT(m_removeAction);
new SyncButtonAndAction(m_removeAction, m_wdgLayerBox->bnDelete, this);
connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRmClicked()));
action = actionManager->createAction("move_layer_up");
Q_ASSERT(action);
new SyncButtonAndAction(action, m_wdgLayerBox->bnRaise, this);
connect(action, SIGNAL(triggered()), this, SLOT(slotRaiseClicked()));
action = actionManager->createAction("move_layer_down");
Q_ASSERT(action);
new SyncButtonAndAction(action, m_wdgLayerBox->bnLower, this);
connect(action, SIGNAL(triggered()), this, SLOT(slotLowerClicked()));
m_changeCloneSourceAction = actionManager->createAction("set-copy-from");
Q_ASSERT(m_changeCloneSourceAction);
connect(m_changeCloneSourceAction, &KisAction::triggered,
this, &LayerBox::slotChangeCloneSourceClicked);
}
void LayerBox::setCanvas(KoCanvasBase *canvas)
{
if (m_canvas == canvas)
return;
setEnabled(canvas != 0);
if (m_canvas) {
m_canvas->disconnectCanvasObserver(this);
m_nodeModel->setDummiesFacade(0, 0, 0, 0, 0);
m_selectionActionsAdapter.reset();
if (m_image) {
KisImageAnimationInterface *animation = m_image->animationInterface();
animation->disconnect(this);
}
disconnect(m_image, 0, this, 0);
disconnect(m_nodeManager, 0, this, 0);
disconnect(m_nodeModel, 0, m_nodeManager, 0);
m_nodeManager->slotSetSelectedNodes(KisNodeList());
}
m_canvas = dynamic_cast(canvas);
if (m_canvas) {
m_image = m_canvas->image();
connect(m_image, SIGNAL(sigImageUpdated(QRect)), &m_thumbnailCompressor, SLOT(start()));
KisDocument* doc = static_cast(m_canvas->imageView()->document());
KisShapeController *kritaShapeController =
dynamic_cast(doc->shapeController());
KisDummiesFacadeBase *kritaDummiesFacade =
static_cast(kritaShapeController);
m_selectionActionsAdapter.reset(new KisSelectionActionsAdapter(m_canvas->viewManager()->selectionManager()));
m_nodeModel->setDummiesFacade(kritaDummiesFacade,
m_image,
kritaShapeController,
m_selectionActionsAdapter.data(),
m_nodeManager);
connect(m_image, SIGNAL(sigAboutToBeDeleted()), SLOT(notifyImageDeleted()));
connect(m_image, SIGNAL(sigNodeCollapsedChanged()), SLOT(slotNodeCollapsedChanged()));
// cold start
if (m_nodeManager) {
setCurrentNode(m_nodeManager->activeNode());
// Connection KisNodeManager -> LayerBox
connect(m_nodeManager, SIGNAL(sigUiNeedChangeActiveNode(KisNodeSP)),
this, SLOT(setCurrentNode(KisNodeSP)));
connect(m_nodeManager,
SIGNAL(sigUiNeedChangeSelectedNodes(QList)),
SLOT(slotNodeManagerChangedSelection(QList)));
}
else {
setCurrentNode(m_canvas->imageView()->currentNode());
}
// Connection LayerBox -> KisNodeManager (isolate layer)
connect(m_nodeModel, SIGNAL(toggleIsolateActiveNode()),
m_nodeManager, SLOT(toggleIsolateActiveNode()));
KisImageAnimationInterface *animation = m_image->animationInterface();
connect(animation, &KisImageAnimationInterface::sigUiTimeChanged, this, &LayerBox::slotImageTimeChanged);
expandNodesRecursively(m_image->rootLayer(), m_filteringModel, m_wdgLayerBox->listLayers);
m_wdgLayerBox->listLayers->scrollTo(m_wdgLayerBox->listLayers->currentIndex());
updateAvailableLabels();
addActionToMenu(m_newLayerMenu, "add_new_paint_layer");
addActionToMenu(m_newLayerMenu, "add_new_group_layer");
addActionToMenu(m_newLayerMenu, "add_new_clone_layer");
addActionToMenu(m_newLayerMenu, "add_new_shape_layer");
addActionToMenu(m_newLayerMenu, "add_new_adjustment_layer");
addActionToMenu(m_newLayerMenu, "add_new_fill_layer");
addActionToMenu(m_newLayerMenu, "add_new_file_layer");
m_newLayerMenu->addSeparator();
addActionToMenu(m_newLayerMenu, "add_new_transparency_mask");
addActionToMenu(m_newLayerMenu, "add_new_filter_mask");
addActionToMenu(m_newLayerMenu, "add_new_colorize_mask");
addActionToMenu(m_newLayerMenu, "add_new_transform_mask");
addActionToMenu(m_newLayerMenu, "add_new_selection_mask");
}
}
void LayerBox::unsetCanvas()
{
setEnabled(false);
if (m_canvas) {
m_newLayerMenu->clear();
}
m_filteringModel->unsetDummiesFacade();
disconnect(m_image, 0, this, 0);
disconnect(m_nodeManager, 0, this, 0);
disconnect(m_nodeModel, 0, m_nodeManager, 0);
m_nodeManager->slotSetSelectedNodes(KisNodeList());
m_canvas = 0;
}
void LayerBox::notifyImageDeleted()
{
setCanvas(0);
}
void LayerBox::updateUI()
{
if (!m_canvas) return;
if (!m_nodeManager) return;
KisNodeSP activeNode = m_nodeManager->activeNode();
if (activeNode != m_activeNode) {
if( !m_activeNode.isNull() )
m_activeNode->disconnect(this);
m_activeNode = activeNode;
if (activeNode) {
KisKeyframeChannel *opacityChannel = activeNode->getKeyframeChannel(KisKeyframeChannel::Opacity.id(), false);
if (opacityChannel) {
watchOpacityChannel(opacityChannel);
} else {
watchOpacityChannel(0);
connect(activeNode.data(), &KisNode::keyframeChannelAdded, this, &LayerBox::slotKeyframeChannelAdded);
}
}
}
m_wdgLayerBox->bnRaise->setEnabled(activeNode && activeNode->isEditable(false) && (activeNode->nextSibling()
|| (activeNode->parent() && activeNode->parent() != m_image->root())));
m_wdgLayerBox->bnLower->setEnabled(activeNode && activeNode->isEditable(false) && (activeNode->prevSibling()
|| (activeNode->parent() && activeNode->parent() != m_image->root())));
m_wdgLayerBox->doubleOpacity->setEnabled(activeNode && activeNode->isEditable(false));
m_wdgLayerBox->cmbComposite->setEnabled(activeNode && activeNode->isEditable(false));
m_wdgLayerBox->cmbComposite->validate(m_image->colorSpace());
if (activeNode) {
- if (activeNode->inherits("KisColorizeMask") ||
- activeNode->inherits("KisLayer")) {
+ if (activeNode->inherits("KisColorizeMask") || activeNode->inherits("KisLayer")) {
m_wdgLayerBox->doubleOpacity->setEnabled(true);
if (!m_wdgLayerBox->doubleOpacity->isDragging()) {
slotSetOpacity(activeNode->opacity() * 100.0 / 255);
}
const KoCompositeOp* compositeOp = activeNode->compositeOp();
if (compositeOp) {
slotSetCompositeOp(compositeOp);
} else {
m_wdgLayerBox->cmbComposite->setEnabled(false);
}
const KisGroupLayer *group = qobject_cast(activeNode.data());
bool compositeSelectionActive = !(group && group->passThroughMode());
m_wdgLayerBox->cmbComposite->setEnabled(compositeSelectionActive);
} else if (activeNode->inherits("KisMask")) {
m_wdgLayerBox->cmbComposite->setEnabled(false);
m_wdgLayerBox->doubleOpacity->setEnabled(false);
}
}
}
/**
* This method is called *only* when non-GUI code requested the
* change of the current node
*/
void LayerBox::setCurrentNode(KisNodeSP node)
{
m_filteringModel->setActiveNode(node);
QModelIndex index = node ? m_filteringModel->indexFromNode(node) : QModelIndex();
m_filteringModel->setData(index, true, KisNodeModel::ActiveRole);
updateUI();
}
void LayerBox::slotModelReset()
{
if(m_nodeModel->hasDummiesFacade()) {
QItemSelection selection;
Q_FOREACH (const KisNodeSP node, m_nodeManager->selectedNodes()) {
const QModelIndex &idx = m_filteringModel->indexFromNode(node);
if(idx.isValid()){
QItemSelectionRange selectionRange(idx);
selection << selectionRange;
}
}
m_wdgLayerBox->listLayers->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
}
updateUI();
}
void LayerBox::slotSetCompositeOp(const KoCompositeOp* compositeOp)
{
KoID opId = KoCompositeOpRegistry::instance().getKoID(compositeOp->id());
m_wdgLayerBox->cmbComposite->blockSignals(true);
m_wdgLayerBox->cmbComposite->selectCompositeOp(opId);
m_wdgLayerBox->cmbComposite->blockSignals(false);
}
// range: 0-100
void LayerBox::slotSetOpacity(double opacity)
{
Q_ASSERT(opacity >= 0 && opacity <= 100);
m_wdgLayerBox->doubleOpacity->blockSignals(true);
m_wdgLayerBox->doubleOpacity->setValue(opacity);
m_wdgLayerBox->doubleOpacity->blockSignals(false);
}
void LayerBox::slotContextMenuRequested(const QPoint &pos, const QModelIndex &index)
{
KisNodeList nodes = m_nodeManager->selectedNodes();
KisNodeSP activeNode = m_nodeManager->activeNode();
if (nodes.isEmpty() || !activeNode) return;
if (m_canvas) {
QMenu menu;
const bool singleLayer = nodes.size() == 1;
if (index.isValid()) {
menu.addAction(m_propertiesAction);
if (singleLayer) {
addActionToMenu(&menu, "layer_style");
}
Q_FOREACH(KisNodeSP node, nodes) {
if (node && node->inherits("KisCloneLayer")) {
menu.addAction(m_changeCloneSourceAction);
break;
}
}
{
KisSignalsBlocker b(m_colorSelector);
m_colorSelector->setCurrentIndex(singleLayer ? activeNode->colorLabelIndex() : -1);
}
menu.addAction(m_colorSelectorAction);
menu.addSeparator();
addActionToMenu(&menu, "cut_layer_clipboard");
addActionToMenu(&menu, "copy_layer_clipboard");
addActionToMenu(&menu, "paste_layer_from_clipboard");
menu.addAction(m_removeAction);
addActionToMenu(&menu, "duplicatelayer");
addActionToMenu(&menu, "merge_layer");
if (singleLayer) {
addActionToMenu(&menu, "flatten_image");
addActionToMenu(&menu, "flatten_layer");
}
menu.addSeparator();
QMenu *selectMenu = menu.addMenu(i18n("&Select"));
addActionToMenu(selectMenu, "select_all_layers");
addActionToMenu(selectMenu, "select_visible_layers");
addActionToMenu(selectMenu, "select_invisible_layers");
addActionToMenu(selectMenu, "select_locked_layers");
addActionToMenu(selectMenu, "select_unlocked_layers");
QMenu *groupMenu = menu.addMenu(i18n("&Group"));
addActionToMenu(groupMenu, "create_quick_group");
addActionToMenu(groupMenu, "create_quick_clipping_group");
addActionToMenu(groupMenu, "quick_ungroup");
QMenu *locksMenu = menu.addMenu(i18n("&Toggle Locks && Visibility"));
addActionToMenu(locksMenu, "toggle_layer_visibility");
addActionToMenu(locksMenu, "toggle_layer_lock");
addActionToMenu(locksMenu, "toggle_layer_inherit_alpha");
addActionToMenu(locksMenu, "toggle_layer_alpha_lock");
if (singleLayer) {
QMenu *addLayerMenu = menu.addMenu(i18n("&Add"));
addActionToMenu(addLayerMenu, "add_new_transparency_mask");
addActionToMenu(addLayerMenu, "add_new_filter_mask");
addActionToMenu(addLayerMenu, "add_new_colorize_mask");
addActionToMenu(addLayerMenu, "add_new_transform_mask");
addActionToMenu(addLayerMenu, "add_new_selection_mask");
QMenu *convertToMenu = menu.addMenu(i18n("&Convert"));
addActionToMenu(convertToMenu, "convert_to_paint_layer");
addActionToMenu(convertToMenu, "convert_to_transparency_mask");
addActionToMenu(convertToMenu, "convert_to_filter_mask");
addActionToMenu(convertToMenu, "convert_to_selection_mask");
addActionToMenu(convertToMenu, "convert_to_file_layer");
QMenu *splitAlphaMenu = menu.addMenu(i18n("S&plit Alpha"));
addActionToMenu(splitAlphaMenu, "split_alpha_into_mask");
addActionToMenu(splitAlphaMenu, "split_alpha_write");
addActionToMenu(splitAlphaMenu, "split_alpha_save_merged");
}
menu.addSeparator();
addActionToMenu(&menu, "show_in_timeline");
if (singleLayer) {
KisNodeSP node = m_filteringModel->nodeFromIndex(index);
if (node && !node->inherits("KisTransformMask")) {
addActionToMenu(&menu, "isolate_layer");
}
addActionToMenu(&menu, "selectopaque");
}
}
menu.exec(pos);
}
}
void LayerBox::slotMinimalView()
{
m_wdgLayerBox->listLayers->setDisplayMode(NodeView::MinimalMode);
}
void LayerBox::slotDetailedView()
{
m_wdgLayerBox->listLayers->setDisplayMode(NodeView::DetailedMode);
}
void LayerBox::slotThumbnailView()
{
m_wdgLayerBox->listLayers->setDisplayMode(NodeView::ThumbnailMode);
}
void LayerBox::slotRmClicked()
{
if (!m_canvas) return;
m_nodeManager->removeNode();
}
void LayerBox::slotRaiseClicked()
{
if (!m_canvas) return;
m_nodeManager->raiseNode();
}
void LayerBox::slotLowerClicked()
{
if (!m_canvas) return;
m_nodeManager->lowerNode();
}
void LayerBox::slotPropertiesClicked()
{
if (!m_canvas) return;
if (KisNodeSP active = m_nodeManager->activeNode()) {
m_nodeManager->nodeProperties(active);
}
}
void LayerBox::slotChangeCloneSourceClicked()
{
if (!m_canvas) return;
m_nodeManager->changeCloneSource();
}
void LayerBox::slotCompositeOpChanged(int index)
{
Q_UNUSED(index);
if (!m_canvas) return;
QString compositeOp = m_wdgLayerBox->cmbComposite->selectedCompositeOp().id();
m_nodeManager->nodeCompositeOpChanged(m_nodeManager->activeColorSpace()->compositeOp(compositeOp));
}
void LayerBox::slotOpacityChanged()
{
if (!m_canvas) return;
m_blockOpacityUpdate = true;
m_nodeManager->nodeOpacityChanged(m_newOpacity);
m_blockOpacityUpdate = false;
}
void LayerBox::slotOpacitySliderMoved(qreal opacity)
{
m_newOpacity = opacity;
m_opacityDelayTimer.start(200);
}
void LayerBox::slotCollapsed(const QModelIndex &index)
{
KisNodeSP node = m_filteringModel->nodeFromIndex(index);
if (node) {
node->setCollapsed(true);
}
}
void LayerBox::slotExpanded(const QModelIndex &index)
{
KisNodeSP node = m_filteringModel->nodeFromIndex(index);
if (node) {
node->setCollapsed(false);
}
}
void LayerBox::slotSelectOpaque()
{
if (!m_canvas) return;
QAction *action = m_canvas->viewManager()->actionManager()->actionByName("selectopaque");
if (action) {
action->trigger();
}
}
void LayerBox::slotNodeCollapsedChanged()
{
expandNodesRecursively(m_image->rootLayer(), m_filteringModel, m_wdgLayerBox->listLayers);
}
inline bool isSelectionMask(KisNodeSP node)
{
return dynamic_cast(node.data());
}
KisNodeSP LayerBox::findNonHidableNode(KisNodeSP startNode)
{
if (KisNodeManager::isNodeHidden(startNode, true) &&
startNode->parent() &&
!startNode->parent()->parent()) {
KisNodeSP node = startNode->prevSibling();
while (node && KisNodeManager::isNodeHidden(node, true)) {
node = node->prevSibling();
}
if (!node) {
node = startNode->nextSibling();
while (node && KisNodeManager::isNodeHidden(node, true)) {
node = node->nextSibling();
}
}
if (!node) {
node = m_image->root()->lastChild();
while (node && KisNodeManager::isNodeHidden(node, true)) {
node = node->prevSibling();
}
}
KIS_ASSERT_RECOVER_NOOP(node && "cannot activate any node!");
startNode = node;
}
return startNode;
}
void LayerBox::slotEditGlobalSelection(bool showSelections)
{
KisNodeSP lastActiveNode = m_nodeManager->activeNode();
KisNodeSP activateNode = lastActiveNode;
KisSelectionMaskSP globalSelectionMask;
if (!showSelections) {
activateNode = findNonHidableNode(activateNode);
}
m_nodeModel->setShowGlobalSelection(showSelections);
globalSelectionMask = m_image->rootLayer()->selectionMask();
// try to find deactivated, but visible masks
if (!globalSelectionMask) {
KoProperties properties;
properties.setProperty("visible", true);
QList masks = m_image->rootLayer()->childNodes(QStringList("KisSelectionMask"), properties);
if (!masks.isEmpty()) {
globalSelectionMask = dynamic_cast(masks.first().data());
}
}
// try to find at least any selection mask
if (!globalSelectionMask) {
KoProperties properties;
QList masks = m_image->rootLayer()->childNodes(QStringList("KisSelectionMask"), properties);
if (!masks.isEmpty()) {
globalSelectionMask = dynamic_cast(masks.first().data());
}
}
if (globalSelectionMask) {
if (showSelections) {
activateNode = globalSelectionMask;
}
}
if (activateNode != lastActiveNode) {
m_nodeManager->slotNonUiActivatedNode(activateNode);
} else if (lastActiveNode) {
setCurrentNode(lastActiveNode);
}
if (showSelections && !globalSelectionMask) {
KisProcessingApplicator applicator(m_image, 0,
KisProcessingApplicator::NONE,
KisImageSignalVector() << ModifiedSignal,
kundo2_i18n("Quick Selection Mask"));
applicator.applyCommand(
new KisLayerUtils::KeepNodesSelectedCommand(
m_nodeManager->selectedNodes(), KisNodeList(),
lastActiveNode, 0, m_image, false),
KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::EXCLUSIVE);
applicator.applyCommand(new KisSetEmptyGlobalSelectionCommand(m_image),
KisStrokeJobData::SEQUENTIAL,
KisStrokeJobData::EXCLUSIVE);
applicator.applyCommand(new KisLayerUtils::SelectGlobalSelectionMask(m_image),
KisStrokeJobData::SEQUENTIAL,
KisStrokeJobData::EXCLUSIVE);
applicator.end();
} else if (!showSelections &&
globalSelectionMask &&
globalSelectionMask->selection()->selectedRect().isEmpty()) {
KisProcessingApplicator applicator(m_image, 0,
KisProcessingApplicator::NONE,
KisImageSignalVector() << ModifiedSignal,
kundo2_i18n("Cancel Quick Selection Mask"));
applicator.applyCommand(new KisSetGlobalSelectionCommand(m_image, 0), KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::EXCLUSIVE);
applicator.end();
}
}
void LayerBox::selectionChanged(const QModelIndexList selection)
{
if (!m_nodeManager) return;
/**
* When the user clears the extended selection by clicking on the
* empty area of the docker, the selection should be reset on to
* the active layer, which might be even unselected(!).
*/
if (selection.isEmpty() && m_nodeManager->activeNode()) {
QModelIndex selectedIndex =
m_filteringModel->indexFromNode(m_nodeManager->activeNode());
m_wdgLayerBox->listLayers->selectionModel()->
setCurrentIndex(selectedIndex, QItemSelectionModel::ClearAndSelect);
return;
}
QList selectedNodes;
Q_FOREACH (const QModelIndex &idx, selection) {
selectedNodes << m_filteringModel->nodeFromIndex(idx);
}
m_nodeManager->slotSetSelectedNodes(selectedNodes);
updateUI();
}
void LayerBox::slotAboutToRemoveRows(const QModelIndex &parent, int start, int end)
{
/**
* Qt has changed its behavior when deleting an item. Previously
* the selection priority was on the next item in the list, and
* now it has shanged to the previous item. Here we just adjust
* the selected item after the node removal. Please take care that
* this method overrides what was done by the corresponding method
* of QItemSelectionModel, which *has already done* its work. That
* is why we use (start - 1) and (end + 1) in the activation
* condition.
*
* See bug: https://bugs.kde.org/show_bug.cgi?id=345601
*/
QModelIndex currentIndex = m_wdgLayerBox->listLayers->currentIndex();
QAbstractItemModel *model = m_filteringModel;
if (currentIndex.isValid() && parent == currentIndex.parent()
&& currentIndex.row() >= start - 1 && currentIndex.row() <= end + 1) {
QModelIndex old = currentIndex;
if (model && end < model->rowCount(parent) - 1) // there are rows left below the change
currentIndex = model->index(end + 1, old.column(), parent);
else if (start > 0) // there are rows left above the change
currentIndex = model->index(start - 1, old.column(), parent);
else // there are no rows left in the table
currentIndex = QModelIndex();
if (currentIndex.isValid() && currentIndex != old) {
m_wdgLayerBox->listLayers->setCurrentIndex(currentIndex);
}
}
}
void LayerBox::slotNodeManagerChangedSelection(const KisNodeList &nodes)
{
if (!m_nodeManager) return;
QModelIndexList newSelection;
Q_FOREACH(KisNodeSP node, nodes) {
newSelection << m_filteringModel->indexFromNode(node);
}
QItemSelectionModel *model = m_wdgLayerBox->listLayers->selectionModel();
if (KritaUtils::compareListsUnordered(newSelection, model->selectedIndexes())) {
return;
}
QItemSelection selection;
Q_FOREACH(const QModelIndex &idx, newSelection) {
selection.select(idx, idx);
}
model->select(selection, QItemSelectionModel::ClearAndSelect);
}
void LayerBox::updateThumbnail()
{
m_wdgLayerBox->listLayers->updateNode(m_wdgLayerBox->listLayers->currentIndex());
}
void LayerBox::slotRenameCurrentNode()
{
m_wdgLayerBox->listLayers->edit(m_wdgLayerBox->listLayers->currentIndex());
}
void LayerBox::slotColorLabelChanged(int label)
{
KisNodeList nodes = m_nodeManager->selectedNodes();
Q_FOREACH(KisNodeSP node, nodes) {
auto applyLabelFunc =
[label](KisNodeSP node) {
node->setColorLabelIndex(label);
};
KisLayerUtils::recursiveApplyNodes(node, applyLabelFunc);
}
}
void LayerBox::updateAvailableLabels()
{
if (!m_image) return;
m_wdgLayerBox->cmbFilter->updateAvailableLabels(m_image->root());
}
void LayerBox::updateLayerFiltering()
{
m_filteringModel->setAcceptedLabels(m_wdgLayerBox->cmbFilter->selectedColors());
}
void LayerBox::slotKeyframeChannelAdded(KisKeyframeChannel *channel)
{
if (channel->id() == KisKeyframeChannel::Opacity.id()) {
watchOpacityChannel(channel);
}
}
void LayerBox::watchOpacityChannel(KisKeyframeChannel *channel)
{
if (m_opacityChannel) {
m_opacityChannel->disconnect(this);
}
m_opacityChannel = channel;
if (m_opacityChannel) {
connect(m_opacityChannel, SIGNAL(sigKeyframeAdded(KisKeyframeSP)), this, SLOT(slotOpacityKeyframeChanged(KisKeyframeSP)));
connect(m_opacityChannel, SIGNAL(sigKeyframeRemoved(KisKeyframeSP)), this, SLOT(slotOpacityKeyframeChanged(KisKeyframeSP)));
connect(m_opacityChannel, SIGNAL(sigKeyframeMoved(KisKeyframeSP)), this, SLOT(slotOpacityKeyframeMoved(KisKeyframeSP)));
connect(m_opacityChannel, SIGNAL(sigKeyframeChanged(KisKeyframeSP)), this, SLOT(slotOpacityKeyframeChanged(KisKeyframeSP)));
}
}
void LayerBox::slotOpacityKeyframeChanged(KisKeyframeSP keyframe)
{
Q_UNUSED(keyframe);
if (m_blockOpacityUpdate) return;
updateUI();
}
void LayerBox::slotOpacityKeyframeMoved(KisKeyframeSP keyframe, int fromTime)
{
Q_UNUSED(fromTime);
slotOpacityKeyframeChanged(keyframe);
}
void LayerBox::slotImageTimeChanged(int time)
{
Q_UNUSED(time);
updateUI();
}
void LayerBox::slotUpdateIcons() {
m_wdgLayerBox->bnAdd->setIcon(KisIconUtils::loadIcon("addlayer"));
m_wdgLayerBox->bnRaise->setIcon(KisIconUtils::loadIcon("arrowupblr"));
m_wdgLayerBox->bnDelete->setIcon(KisIconUtils::loadIcon("deletelayer"));
m_wdgLayerBox->bnLower->setIcon(KisIconUtils::loadIcon("arrowdown"));
m_wdgLayerBox->bnProperties->setIcon(KisIconUtils::loadIcon("properties"));
m_wdgLayerBox->bnDuplicate->setIcon(KisIconUtils::loadIcon("duplicatelayer"));
// call child function about needing to update icons
m_wdgLayerBox->listLayers->slotUpdateIcons();
}
void LayerBox::slotUpdateThumbnailIconSize()
{
KisConfig cfg(false);
cfg.setLayerThumbnailSize(thumbnailSizeSlider->value());
// this is a hack to force the layers list to update its display and
// re-layout all the layers with the new thumbnail size
resize(this->width()+1, this->height()+1);
resize(this->width()-1, this->height()-1);
}
#include "moc_LayerBox.cpp"