@@ -12,6 +12,8 @@ import (
1212// Cursor is
1313type Cursor struct {
1414 widgets.QWidget
15+
16+ smoothMoveAnimation * core.QPropertyAnimation
1517 charCache * Cache
1618 font * Font
1719 fallbackfonts []* Font
@@ -692,9 +694,10 @@ func (c *Cursor) redraw() {
692694
693695// paint() is to request update cursor widget.
694696// NOTE: This function execution may not be necessary.
695- // This is because move() is performed in the redraw() of the cursor,
696- // and it seems that paintEvent is fired inside
697- // the cursor widget in conjunction with this move processing.
697+ //
698+ // This is because move() is performed in the redraw() of the cursor,
699+ // and it seems that paintEvent is fired inside
700+ // the cursor widget in conjunction with this move processing.
698701func (c * Cursor ) paint () {
699702 if editor .isKeyAutoRepeating {
700703 return
@@ -703,6 +706,50 @@ func (c *Cursor) paint() {
703706 c .Update ()
704707}
705708
709+ func (c * Cursor ) initializeOrReuseSmoothMoveAnimation () {
710+ if c .smoothMoveAnimation == nil {
711+ c .smoothMoveAnimation = core .NewQPropertyAnimation2 (c , core .NewQByteArray2 ("animationProp" , len ("animationProp" )), c )
712+ c .smoothMoveAnimation .SetDuration (int (editor .config .Cursor .Duration ))
713+ c .smoothMoveAnimation .SetStartValue (core .NewQVariant10 (float64 (0.01 )))
714+ c .smoothMoveAnimation .SetEndValue (core .NewQVariant10 (1 ))
715+ c .smoothMoveAnimation .SetEasingCurve (core .NewQEasingCurve (core .QEasingCurve__OutExpo ))
716+
717+ c .smoothMoveAnimation .ConnectValueChanged (func (value * core.QVariant ) {
718+ if ! c .doAnimate {
719+ c .delta = 0
720+ c .deltax = 0
721+ c .deltay = 0
722+ c .move ()
723+ c .paint ()
724+ return
725+ }
726+ ok := false
727+ v := value .ToDouble (& ok )
728+ if ! ok {
729+ return
730+ }
731+
732+ c .delta = v
733+ c .deltax = (c .x - c .xprime ) * v
734+ c .deltay = (c .y - c .yprime ) * v
735+
736+ if v == 1.0 {
737+ c .delta = 0
738+ c .deltax = 0
739+ c .deltay = 0
740+ c .doAnimate = false
741+ }
742+
743+ if c .doAnimate {
744+ c .animationStartX = c .xprime
745+ c .animationStartY = c .yprime
746+ }
747+
748+ c .move ()
749+ })
750+ }
751+ }
752+
706753func (c * Cursor ) animateMove () {
707754 if ! c .doAnimate {
708755 return
@@ -711,61 +758,13 @@ func (c *Cursor) animateMove() {
711758 return
712759 }
713760
714- // process smooth scroll
715- a := core .NewQPropertyAnimation2 (c , core .NewQByteArray2 ("animationProp" , len ("animationProp" )), c )
716- a .ConnectValueChanged (func (value * core.QVariant ) {
717- if ! c .doAnimate {
718- c .delta = 0
719- c .deltax = 0
720- c .deltay = 0
721- c .move ()
722- c .paint ()
723- return
724- }
725- ok := false
726- v := value .ToDouble (& ok )
727- if ! ok {
728- return
729- }
761+ c .initializeOrReuseSmoothMoveAnimation ()
730762
731- c .delta = v
732- c .deltax = (c .x - c .xprime ) * v
733- c .deltay = (c .y - c .yprime ) * v
734-
735- if v == 1.0 {
736- c .delta = 0
737- c .deltax = 0
738- c .deltay = 0
739- c .doAnimate = false
740- }
741-
742- if c .doAnimate {
743- c .animationStartX = c .xprime
744- c .animationStartY = c .yprime
745- }
763+ if c .smoothMoveAnimation .State () == core .QAbstractAnimation__Running {
764+ c .smoothMoveAnimation .Stop ()
765+ }
746766
747- c .move ()
748- })
749- duration := editor .config .Cursor .Duration
750- a .SetDuration (int (duration ))
751- a .SetStartValue (core .NewQVariant10 (float64 (0.01 )))
752- a .SetEndValue (core .NewQVariant10 (1 ))
753- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__InOutCirc))
754- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__OutQuart))
755- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__OutExpo))
756- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__OutQuint))
757- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__InOutCubic))
758- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__InOutQuint))
759- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__Linear))
760- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__InQuart))
761- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__OutCubic))
762- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__InOutQuart))
763- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__OutInQuart))
764- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__InOutExpo))
765- a .SetEasingCurve (core .NewQEasingCurve (core .QEasingCurve__OutCirc ))
766- // a.SetEasingCurve(core.NewQEasingCurve(core.QEasingCurve__InCubic))
767-
768- a .Start (core .QAbstractAnimation__DeletionPolicy (core .QAbstractAnimation__DeleteWhenStopped ))
767+ c .smoothMoveAnimation .Start (core .QAbstractAnimation__DeletionPolicy (core .QAbstractAnimation__KeepWhenStopped ))
769768}
770769
771770func (c * Cursor ) resize (width , height int ) {
0 commit comments