Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Help understanding pinch/push code

    General and Desktop
    2
    7
    176
    Loading More Posts
    • 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
      Circuits last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • C
          Circuits @mrjj last edited by

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

           // pimpl
              struct Data; Data& _;
          
          mrjj 1 Reply Last reply Reply Quote 1
          • mrjj
            mrjj Lifetime Qt Champion @Circuits last edited by 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 1 Reply Last reply Reply Quote 0
            • C
              Circuits @mrjj last edited by 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.

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @Circuits last edited by

                @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 Reply Quote 0
                • C
                  Circuits @mrjj last edited by Circuits

                  @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 Reply Quote 0
                  • First post
                    Last post