Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7863 in orxonox.OLD for trunk/src/lib/gui/qt_gui


Ignore:
Timestamp:
May 25, 2006, 6:02:27 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: also catching mouse-events

Location:
trunk/src/lib/gui/qt_gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/gui/qt_gui/gui_control.cc

    r7862 r7863  
    3030#include <QtCore/QEvent>
    3131#include <QtGui/QKeyEvent>
     32#include <QtGui/QMouseEvent>
    3233
    3334#include "sdlincl.h"
     
    9394    Saveable::load();
    9495    this->setText(QString().fromStdString(this->value().getString()));
    95     printf("%s\n", this->value().getString().c_str());
    9696  }
    9797
     
    105105  bool GuiControlInput::event ( QEvent * e )
    106106  {
    107     if (!this->bListening || e->type() != QEvent::KeyPress)
    108       return QPushButton::event(e);
    109 
    110 
    111     this->releaseKeyboard();
    112     this->bListening = true;
    113     if (e->type() == QEvent::KeyPress)
     107    if (this->bListening && (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress))
    114108    {
    115       QKeyEvent* event = dynamic_cast<QKeyEvent*>(e);
    116 
    117       int ev = QtKToSDLK(event->key());
    118       if (ev != -1)
     109      this->bListening = false;
     110      this->releaseKeyboard();
     111      this->releaseMouse();
     112      /// KEY IS PRESSED:
     113      if (e->type() == QEvent::KeyPress)
    119114      {
    120         this->setText(QString().fromStdString(SDLKToKeyname(ev)));
     115        QKeyEvent* event = dynamic_cast<QKeyEvent*>(e);
     116
     117        int ev = QtKToSDLK(event->key());
     118        if (ev != -1)
     119        {
     120          this->setText(QString().fromStdString(SDLKToKeyname(ev)));
     121        }
     122        return true;
    121123      }
     124      /// MOUSE BUTTON PRESSED:
     125      if (e->type() == QEvent::MouseButtonPress)
     126      {
     127        QMouseEvent* event = dynamic_cast<QMouseEvent*>(e);
     128        if (event->button() != Qt::NoButton)
     129        {
     130          this->setText(QString().fromStdString(QtKToString(event->button())));
     131        }
     132
     133      }
     134
    122135    }
    123     return true;
     136
     137    return QPushButton::event(e);
    124138  }
    125139
     
    128142    this->bListening = true;
    129143    this->grabKeyboard();
     144    this->grabMouse();
    130145  }
    131146
     
    271286    }
    272287  }
     288
     289  std::string GuiControlInput::QtKToString(int button)
     290  {
     291    if( button == Qt::LeftButton) return "BUTTON_LEFT";
     292    if( button == Qt::MidButton) return "BUTTON_MIDDLE";
     293    if( button == Qt::RightButton) return "BUTTON_RIGHT";
     294    //if( button == Qt::) return "BUTTON_WHEELUP";
     295    //if( button == EV_MOUSE_BUTTON_WHEELDOWN) return "BUTTON_WHEELDOWN";
     296    return "UNKNOWN";
     297  }
     298
    273299}
  • trunk/src/lib/gui/qt_gui/gui_control.h

    r7862 r7863  
    3838
    3939    static int QtKToSDLK(int key);
     40    static std::string QtKToString(int button);
    4041
    4142    public slots:
Note: See TracChangeset for help on using the changeset viewer.