Changeset 8630:b45cfbba67e4 in orange


Ignore:
Timestamp:
08/08/11 08:46:45 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
5474c28f4fb87a3c5829ed6df53b3aabc3ebca0c
Message:

Add item move animation to C++

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/plot/owplot.py

    r8629 r8630  
    887887         
    888888    def mousePressEvent(self, event): 
     889        self.static_click = True 
     890        self._pressed_mouse_button = event.button() 
     891        self._pressed_mouse_pos = event.pos() 
     892 
    889893        if self.mousePressEventHandler and self.mousePressEventHandler(event): 
    890894            event.accept() 
     
    896900        point = self.mapToScene(event.pos()) 
    897901 
    898         self.static_click = True 
    899         self._pressed_mouse_button = event.button() 
    900         self._pressed_mouse_pos = event.pos() 
    901902        if event.button() == Qt.LeftButton and self.state == PANNING: 
    902903            self._last_pan_pos = point 
     
    906907             
    907908    def mouseMoveEvent(self, event): 
     909        if event.buttons() and (self._pressed_mouse_pos - event.pos()).manhattanLength() > qApp.startDragDistance(): 
     910            self.static_click = False 
     911         
    908912        if self.mouseMoveEventHandler and self.mouseMoveEventHandler(event): 
    909913            event.accept() 
    910914            return 
    911915             
    912         if event.buttons() and (self._pressed_mouse_pos - event.pos()).manhattanLength() > qApp.startDragDistance(): 
    913             self.static_click = False 
    914          
    915916        if self.isLegendEvent(event, QGraphicsView.mouseMoveEvent): 
    916917            return 
  • orange/OrangeWidgets/plot/owtools.py

    r8628 r8630  
    9393        :type duration: int 
    9494    ''' 
    95     for a in _animations: 
    96         if a.state() == QPropertyAnimation.Stopped: 
    97             _animations.remove(a) 
    9895    if use_animations: 
    99         a = QPropertyAnimation(item, 'pos') 
    100         a.setStartValue(item.pos()) 
    101         a.setEndValue(pos) 
    102         if duration: 
    103             a.setDuration(duration) 
    104         a.start(QPropertyAnimation.KeepWhenStopped) 
    105         _animations.append(a) 
     96        if not duration: 
     97            duration = 250 
     98        orangeplot.PlotItem.move_item(item, pos, duration) 
    10699    else: 
    107100        item.setPos(x, y) 
  • source/orangeplot/plotitem.cpp

    r8613 r8630  
    11#include "plotitem.h" 
    22#include "plot.h" 
     3 
     4#include <QtCore/QVariantAnimation> 
    35 
    46// Copied from OrangeWidgets/plot/owconstants.py 
    57const int xBottom = 2; 
    68const int yLeft = 0; 
     9 
     10class MoveAnimation : public QVariantAnimation 
     11{ 
     12public: 
     13    MoveAnimation(QGraphicsItem* item, const QPointF& pos, int duration); 
     14    virtual void updateCurrentValue(const QVariant& value); 
     15private: 
     16    QGraphicsItem* m_item; 
     17}; 
     18 
     19MoveAnimation::MoveAnimation(QGraphicsItem* item, const QPointF& pos, int duration): QVariantAnimation() 
     20{ 
     21    m_item = item; 
     22    setStartValue(item->pos()); 
     23    setEndValue(pos); 
     24    setDuration(duration); 
     25} 
     26 
     27void MoveAnimation::updateCurrentValue(const QVariant& value) 
     28{ 
     29    m_item->setPos(value.toPointF()); 
     30} 
     31 
    732 
    833PlotItem::PlotItem(QGraphicsItem* parent, QGraphicsScene* scene): QGraphicsItem(parent, scene),  
     
    111136} 
    112137 
     138void PlotItem::move_item(QGraphicsItem* item, const QPointF& pos, int duration) 
     139{ 
     140    MoveAnimation* m = new MoveAnimation(item, pos, duration); 
     141    m->start(QAbstractAnimation::DeleteWhenStopped); 
     142} 
     143 
    113144void PlotItem::set_data_rect(const QRectF& dataRect) { 
    114145    m_dataRect = dataRect; 
  • source/orangeplot/plotitem.h

    r8627 r8630  
    3333     
    3434    static QRectF rect_from_data(const QList<double>& x_data, const QList<double>& y_data); 
     35    static void move_item(QGraphicsItem* item, const QPointF& pos, int duration = 250); 
    3536     
    3637    bool is_auto_scale() const; 
  • source/orangeplot/plotitem.sip

    r8613 r8630  
    3333     
    3434    static QRectF rect_from_data(const QList<double>& x_data, const QList<double>& y_data); 
     35    static void move_item(QGraphicsItem* item, const QPointF& pos, int duration = 250); 
    3536     
    3637    bool is_auto_scale() const; 
Note: See TracChangeset for help on using the changeset viewer.