On Thursday 30 October 2003 2:00 pm, Ronald Florence wrote:
> Angus Leeming <[EMAIL PROTECTED]> writes:
> > The fix is trivial (for Qt too) and requires that
> > LyX responds only to a subset of mouse events from the underlying
> > X11, MacOS or Win32 graphics libraries. In the xforms frontend we use
> > a timer, so:
> >         // The timer runs for 200ms
> >         static Timer timer(200);
> >         if (timer.running())
> >                 return;
> >         timer.start();
> >         dispatch(mouse_event_to_the_lyx_core);
> >
> > This could go in, almost as is, to the mouseEventHandler in
> > QContentPane.C. Feel free to try ;-)
>
> Is this fix going into LyX-1.3.4?

In order for any fix to go in, I'd need to know the Qt equivalent of 
XEvent::xmotion.[x,y]. (Ie, the current position of the mouse cursor). 
Thereafter, I'd anticipate that QContentPane::mouseMoveEvent woudl be 
modified so that it looks something like the equivalent code in 
XWorkArea::work_area_handler.

Maybe this information is e->x(), e->y(), but I'm not sure of the difference 
anymore between X11's ev->xmotion.[x,y] and ev->xbutton.[x,y].

So, Qt gurus...
Angus


void QContentPane::mouseMoveEvent(QMouseEvent * e)
{
        
        FuncRequest cmd
                (LFUN_MOUSE_MOTION, e->x(), e->y(), q_motion_state(e->state()));
        wa_->dispatch(cmd);
}


int XWorkArea::work_area_handler(FL_OBJECT * ob, int event,
                                 FL_Coord, FL_Coord,
                                 int key, void * xev)
{
        XEvent * ev = static_cast<XEvent*>(xev);
        XWorkArea * area = static_cast<XWorkArea*>(ob->u_vdata);

        if (!area)
                return 1;

        switch (event) {

        case FL_DRAG: {
                if (!ev || !area->scrollbar)
                        break;

                int const drag_x = ev->xmotion.x;
                int const drag_y = ev->xmotion.y;
                int const area_y = ob->y;
                int const area_h = ob->h;

                // Check if the mouse is above or below the workarea
                if (drag_y <= area_y || drag_y >= area_y + area_h) {
                        // The mouse button is depressed and we are outside the
                        // workarea. That means we are simultaneously selecting
                        // text and scrolling the view.
                        // Use a Timeout to react to a drag events only every
                        // 200ms. All intervening events are discarded,
                        // allowing the user to control position easily.
                        static int const discard_interval = 200;
                        static Timeout timeout(discard_interval);

                        if (timeout.running())
                                break;
                        // The timeout is not running, so process the
                        // event, first starting the timeout to discard future
                        // events.
                        timeout.start();
                }

                static int x_old = -1;
                static int y_old = -1;
                static double scrollbar_value_old = -1.0;

                double const scrollbar_value =
                        fl_get_scrollbar_value(area->scrollbar);

                if (drag_x != x_old || drag_y != y_old ||
                    scrollbar_value != scrollbar_value_old) {
                        x_old = drag_x;
                        y_old = drag_y;
                        scrollbar_value_old = scrollbar_value;

                        lyxerr[Debug::WORKAREA] << "Workarea event: DRAG"
                                                << endl;

                        // It transpires that ev->xbutton.button == 0 when
                        // the mouse is dragged, so it cannot be used to
                        // initialise x_button_state and hence FuncRequest.

                        // The 'key' that is passed into the function does
                        // contain the necessary info, however.

                        // It is for this reason that x_button_state has
                        // been modified to work with key
                        // rather than ev->xbutton.button.

                        // Angus 15 Oct 2002.
                        FuncRequest cmd(LFUN_MOUSE_MOTION,
                                        ev->xbutton.x - ob->x,
                                        ev->xbutton.y - ob->y,
                                        x_button_state(key));
                        area->dispatch(cmd);
                }
                break;
        }

Reply via email to