Permalink
Browse files

Animated cubics at last(cubic_demo05)

Notice: a severe qtruby bug may be present. Patch is inside this commit.
  • Loading branch information...
1 parent 97b43ef commit 2889b982d281ed1d3525e83e0cdc46af425fd5f7 @EugeneBrazwick committed Oct 24, 2010
View
4 README
@@ -19,6 +19,10 @@ BUILD: just run
rake
in the toplevel dir.
+Hm.. qtruby4.6.3.1 contains a bug. A simple 'Qt::Variant::new(0.0)' immediately fails!
+To fix patch it:
+ sudo patch -p0 -E < qtruby4631.patch
+
INSTALL: cannot be done yet. But isn't really required at the moment.
Current state (oct 6 2010)
@@ -20,11 +20,11 @@ def initialize parent, qtc
# notice: these can no longer be queried....
def enabler value = nil, &block
- DynamicAttribute.new(self, :enabled, value, &block)
+ DynamicAttribute.new(self, :enabled, TrueClass, value, &block)
end
def disabler value = nil, &block
- DynamicAttribute.new(self, :disabled, value, &block)
+ DynamicAttribute.new(self, :disabled, TrueClass, value, &block)
end
public
View
@@ -33,7 +33,14 @@ def postSetup
end
end
- protected
+ define_simple_setter :loopCount
+
+ def looping
+ @qtc.loopCount = -1
+ end
+
+ protected # Animation methods
+
attr_writer :autostart
def autostart value = nil
@@ -44,13 +51,17 @@ def autostart value = nil
def autostart?
@autostart
end
- public
+
+ public # Animation methods
+
def addTo parent, hash, &block
parent.addAnimation self, hash, &block
end
def addAnimation anim, hash, &block
super
+# tag "appending #{anim.qtc} to group #@qtc"
+ @qtc.addAnimation(anim.qtc)
anim.autostart = false
end
@@ -59,5 +70,5 @@ def postSetup
end
- end
-end
+ end #class Animation
+end # module Reform
@@ -11,7 +11,8 @@ class AttributeAnimation < Animation
def initialize parent, qtc
super
# tag "#{self}.new(#{parent}, #{qtc}), setting propertyName of anim to 'value'"
- @qtc.setTargetObject(parent)
+ @qtc.setTargetObject(dynamicParent)
+# tag "TargetObject = #{@qtc.targetObject}"
@qtc.propertyName = 'value' # See DynamicAttribute
end
@@ -32,17 +33,32 @@ def states stateid_value_hash
end
end
+ # it seems to me that easing should be set per statevalue. And Qt uses the trajectory
+ # between states...
+ EasingMap = { linear: Qt::EasingCurve::Linear,
+ quad: Qt::EasingCurve::InOutQuad,
+ cubic: Qt::EasingCurve::InOutCubic,
+ sine: Qt::EasingCurve::InOutSine,
+ elastic: Qt::EasingCurve::OutElastic,
+ back: Qt::EasingCurve::OutBack,
+ bounce: Qt::EasingCurve::OutBounce
+ }
+
def easing v
- @qtc.easingCurve = Qt::EasingCurve::OutElastic
+ @qtc.easingCurve = case v
+ when Qt::EasingCurve then v
+ when Symbol then Qt::EasingCurve.new(EasingMap[v] || Qt::EasingCurve::Linear)
+ else Qt::EasingCurve.new(v)
+ end
end
def startValue *value
# tag "start, attrib=#@attrib"
- @qtc.startValue = parent.value2variant(*value)
+ @qtc.startValue = @qtc.targetObject.value2variant(*value)
end
def stopValue *value
- @qtc.endValue = parent.value2variant(*value)
+ @qtc.endValue = @qtc.targetObject.value2variant(*value)
end
# alias :startValue :start
View
@@ -58,12 +58,12 @@ def initialize attrib
=end
class DynamicAttribute < Control
- private
+ private # DynamicAttribute methods
- def initialize parent, propertyname, quickyhash = nil, &block
+ def initialize parent, propertyname, klass, quickyhash = nil, &block
# tag "DynamicAttribute.new(#{parent}, :#{propertyname})"
super(parent)
- @propertyname = propertyname
+ @propertyname, @klass = propertyname, klass
setup(quickyhash, &block) if quickyhash || block
end
@@ -75,6 +75,12 @@ def through_state states2values
end
end
+ def sequence quickyhash = nil, &block
+ require_relative 'animations/sequentialanimation'
+ setProperty('value', value2variant(:default))
+ SequentialAnimation.new(self, Qt::SequentialAnimationGroup.new(self)).setup(quickyhash, &block)
+ end
+
def animation quickyhash = nil, &block
require_relative 'animations/attributeanimation'
# tag "Creating Qt::Variant of value"
@@ -102,25 +108,31 @@ def event e
end
def value2variant *value
- case @propertyname
- when :brush
+ case
+ when @klass == Qt::Brush
color = Graphical.color(*value)
# tag "Qt::Variant.new(#{color})"
Qt::Variant::fromValue(color)
- when :geometry
+ when @klass == Qt::Rect
Qt::Variant::fromValue(case value[0]
when :default then Qt::Rect.new
when Qt::Rect then value[0]
else Qt::Rect.new(*value) #.tap{|r| tag "creating value(#{r.inspect})"}
end)
- when :geometryF
+ when @klass == Qt::RectF
Qt::Variant::fromValue(case value[0]
when :default then Qt::RectF.new
when Qt::RectF then value[0]
else Qt::RectF.new(*value) #.tap{|r| tag "creating value(#{r.inspect})"}
end)
+ when @klass == Float
+# debug Qt::DebugLevel::High do
+ f = value[0] == :default ? 0.0 : value[0]
+# tag "value2variant, value = #{value.inspect}, f = #{f.inspect}, #{f.class}"
+ Qt::Variant::new(f)
+# end
else
- raise Error, tr("Not implemented: animation for property '#@propertyname'")
+ raise Error, tr("Not implemented: animation for property '#@propertyname', klass=#@klass")
end
end
@@ -139,6 +151,10 @@ def applyModel data, model = nil
# properties 'value'
+ def dynamicParent
+ self
+ end
+
end # class DynamicAttribute
DynamicProperty = DynamicAttribute
@@ -194,8 +210,7 @@ def geometry x = nil, y = nil, w = nil, h = nil, &block
q = effective_qwidget
return q.geometry unless x || w || block
case x
- when nil then DynamicAttribute.new(self, :geometry).setup(nil, &block)
- when Hash, Proc then DynamicAttribute.new(self, :geometry).setup(x, &block)
+ when nil, Hash, Proc then DynamicAttribute.new(self, :geometry, Qt::Rect).setup(x, &block)
else
# @requested_size = w, h
if x or y
@@ -254,6 +269,14 @@ def no_signals
end
end
+ def debug level
+ old = Qt::debug_level
+ Qt::debug_level = level
+ yield
+ ensure
+ Qt::debug_level = old
+ end
+
# shortcut. executes the block every ms milliseconds
def timer_interval timeout_in_ms, &block
start_timer(timeout_in_ms)
@@ -772,6 +795,11 @@ def geometry=(*value)
alias :containingForm :containing_form
+ # same as containingForm
+ def dynamicParent
+ parent.dynamicParent
+ end
+
# Qt control that is wrapped
attr :qtc
@@ -6,45 +6,50 @@
Same as demo05, but with two animations
+ BROKEN!!! FIXME
+
=end
require 'reform/app'
Reform::app {
statemachine {
states :s1, :s2, :s3
}
- parallelanimation name :anim
- scene {
- name :myScene
- rect {
- brush {
-# tag "Creating animation :anim"
- animation {
- appendto :anim
- states s1: :blue, s2: :red, s3: :yellow
- duration 1000.ms
+ mainwindow {
+
+ parallelanimation name: :anim
+ scene {
+ name :myScene
+ rect {
+ brush {
+ # tag "Creating animation :anim"
+ animation {
+ appendto :anim
+ states s1: :blue, s2: :red, s3: :yellow
+ duration 1000.ms
+ }
}
}
- }
- rect {
- brush {
-# tag "Creating animation :anim"
- animation {
- appendto :anim
- states s1: :blue, s2: :yellow, s3: :red
- duration 1000.ms
+ rect {
+ brush {
+ # tag "Creating animation :anim"
+ animation {
+ appendto :anim
+ states s1: :blue, s2: :yellow, s3: :red
+ duration 1000.ms
+ }
}
}
}
- }
- button {
- text tr('Click Me')
- whenClicked transitions [{from: :s1, to: :s2, animation: :anim},
- {from: :s2, to: :s3, animation: :anim},
- {from: :s3, to: :s1, animation: :anim}]
- }
- canvas {
- sizeHint 200
- scene :myScene
+ button {
+ text tr('Click Me')
+ whenClicked transitions [{from: :s1, to: :s2, animation: :anim},
+ {from: :s2, to: :s3, animation: :anim},
+ {from: :s3, to: :s1, animation: :anim}]
+ }
+ canvas {
+ sizeHint 200
+ scene :myScene
+ }
}
}
@@ -0,0 +1,40 @@
+
+# Copyright (c) 2010 Eugene Brazwick
+
+=begin
+ An important part of midibox will be the connection drawing using cubics.
+
+ This should be as automatic as possible
+
+ Let's develop some API.
+
+ Painterpath is a good starting point and a way to
+ display these is by constructing a Qt::GraphicsPathItem.
+ It would be nice if you could build the path.
+=end
+
+require 'reform/app'
+
+# introducing graphicspath
+
+Reform::app {
+ mainwindow {
+ sizeHint 400, 320
+ canvas {
+ # graphicspath is calculated once and it will be possible to duplicate them
+ # with a different matrix.
+ # However, you cannot change a part of the path. Only set a completely new path.
+# tag "calling #{self}::pen"
+ pen {
+# tag "self=#{self}"
+ join :round
+ size 7
+ }
+ graphicspath {
+# ellipse position: [100, 100], size: [200, 100]
+ line 0,0, 100,0, 100,100, 0,100, :close
+ # graphicspath ..... recursion should be possible
+ }
+ }
+ }
+}
@@ -0,0 +1,38 @@
+
+# Copyright (c) 2010 Eugene Brazwick
+
+=begin
+ An important part of midibox will be the connection drawing using cubics.
+
+ This should be as automatic as possible
+
+ Let's develop some API.
+
+ Painterpath is a good starting point and a way to
+ display these is by constructing a Qt::GraphicsPathItem.
+ It would be nice if you could build the path.
+
+ -------------------------------
+ Activepath.
+ The fun starts now!
+
+=end
+
+
+require 'reform/app'
+
+Reform::app {
+ mainwindow {
+ sizeHint 400, 320
+ canvas {
+ pen {
+ join :round
+ size 7
+ }
+ # the vertices on an activepath can be moved freely
+ activepath {
+ line 0,0, 100,0, 100,100, 0,100, :close
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 2889b98

Please sign in to comment.