Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help understanding pinch/push code
QtWS25 Last Chance

Help understanding pinch/push code

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 626 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    I need some help understanding how this pinch/push code works. The logic is backwards in that a pinch is zooming in and a push is zooming out. It would seem to me that I can fix this by flipping x and y in the pinchAreaStarted() function but that is just a hunch. What's happening in the actual code is escaping me, here is the code:

    bool MapItem::pinchAreaStarted(QPointF, QPointF startCenter, QPointF, qreal scale, qreal, qreal angle, qreal, qreal, QPointF, QPointF, QPointF, QPointF, int, bool accepted)
    {
        int x = (int)startCenter.x();
        int y = (int)(height() - startCenter.y());
    
        _.ui.pinch        = true;  _.ui.pinchStart        = { x, y };
        _.ui.press        = false; _.ui.pressStart        = { INT_MAX, INT_MAX };
        _.ui.pressAndHold = false; _.ui.pressAndHoldStart = { INT_MAX, INT_MAX };
        _.ui.dragging     = false;    
        OnZoom(_.ui.pinchStart, scale, angle, true);
    
        return accepted;
    }
    
    void MapItem::OnZoom(QPoint, qreal scale, qreal, bool first)
    {
        if (first) { Q_ASSERT(events.empty()); _.zoomStart = _.CurrentZoomLevel(); }
    #if 0
        qreal factor = scale < 1 ? 2 : 0.5;
        qreal zoom = _.zoomStart + (scale /*- 1.0*/) * factor;
    #else
        qreal factor = scale < 1 ? 1 : .1;
        qreal zoom = _.zoomStart + (scale < 1 ? scale - 1 : scale) * factor;
    #endif
        _.SetZoomLevel(zoom);
    }
    
    void SetZoomLevel(qreal zoom) {
            pThis->events.enqueue({MapItem::Z, {zoom, NAN}});
            Update();
        }
    

    I do not understand the significance of the ( ._ )'s is that simply how you address QPoint variables?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      That looks somewhat odd ?
      If you place the cursor on the _ and press F2 what is it declared as ?

      C 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        That looks somewhat odd ?
        If you place the cursor on the _ and press F2 what is it declared as ?

        C Offline
        C Offline
        Circuits
        wrote on last edited by
        #3

        @mrjj Oh right.. okay so here's the declaration apparently it was called _ , not sure how I feel about that:

         // pimpl
            struct Data; Data& _;
        
        mrjjM 1 Reply Last reply
        1
        • C Circuits

          @mrjj Oh right.. okay so here's the declaration apparently it was called _ , not sure how I feel about that:

           // pimpl
              struct Data; Data& _;
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Circuits
          While valid, it seems like a odd name for it, normally the pimpl is named d
          https://wiki.qt.io/D-Pointer
          However in this case it seems the name _ was used.

          Anyway, if you read it as
          DataRef
          it reads better

          It seems like a pimpl impl. but im not 100% sure its used as such.

          C 1 Reply Last reply
          0
          • mrjjM mrjj

            @Circuits
            While valid, it seems like a odd name for it, normally the pimpl is named d
            https://wiki.qt.io/D-Pointer
            However in this case it seems the name _ was used.

            Anyway, if you read it as
            DataRef
            it reads better

            It seems like a pimpl impl. but im not 100% sure its used as such.

            C Offline
            C Offline
            Circuits
            wrote on last edited by Circuits
            #5

            @mrjj Agreed, either way I am not sure how these methods work exactly. I am just going to assume that switching:

            _.ui.pinchStart  = {x, y} 
            

            too

            _.ui.pinchStart  = {y, x} 
            

            will reverse the logic for me. If that doesn't do it than I am not sure what will. Sort of sucks the hardware is being used. Usually, when I want to learn something new about c++, I can just test things until I get a better idea of what's happening.

            mrjjM 1 Reply Last reply
            0
            • C Circuits

              @mrjj Agreed, either way I am not sure how these methods work exactly. I am just going to assume that switching:

              _.ui.pinchStart  = {x, y} 
              

              too

              _.ui.pinchStart  = {y, x} 
              

              will reverse the logic for me. If that doesn't do it than I am not sure what will. Sort of sucks the hardware is being used. Usually, when I want to learn something new about c++, I can just test things until I get a better idea of what's happening.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Circuits
              Hi
              Yes that will contain no funky side effects.
              It simply say

              MyDataRef.ui.pinchStart = {y, x}

              so go ahead and check if it fixes your actual issue.

              C 1 Reply Last reply
              0
              • mrjjM mrjj

                @Circuits
                Hi
                Yes that will contain no funky side effects.
                It simply say

                MyDataRef.ui.pinchStart = {y, x}

                so go ahead and check if it fixes your actual issue.

                C Offline
                C Offline
                Circuits
                wrote on last edited by Circuits
                #7

                @mrjj Unfortunately that didn't work. I was able to invert the zoom for the scroll wheel. The only diffrence between the zoom for the scroll wheel and the one for pinch/push is:

                Used by pinch/push

                    void SetZoomLevel(qreal zoom) {
                        pThis->events.enqueue({MapItem::Z, {-zoom, NAN}});
                        Update();
                    }
                

                and
                Used by scroll wheel

                    void Zoom(bool in) {
                        pThis->events.enqueue({MapItem::Z, { (in?1:-1) * std::numeric_limits<qreal>::max(), NAN}});
                        Update();
                    }
                

                I find it odd that both are using the same enqueue function but are passing seemingly different arguments, here is that function:

                inline void enqueue(const T &t) { QList<T>::append(t); }
                

                All I did to invert the scroll wheel functionality was to change:

                (in?-1:1)
                

                too

                (in?1:-1)
                

                so I guess I will try sending the enqueue -zoom instead of zoom. I am really just grasping at straws here, perhaps this will work.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved