Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/Qt/pixwin is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef toolx_Qt_pixwin
0005 #define toolx_Qt_pixwin
0006 
0007 #include <QtCore/qglobal.h> //For QT_VERSION.
0008 
0009 #if QT_VERSION < 0x050000
0010 #include <QtGui/qwidget.h>
0011 #else
0012 #include <QtWidgets/qwidget.h>
0013 #endif
0014 
0015 #include <QtGui/qevent.h>
0016 #include <QtGui/qpainter.h>
0017 
0018 #include <tools/sg/zb_viewer>
0019 #include <tools/sg/device_interactor>
0020 
0021 #ifdef TOOLS_MEM
0022 #include <tools/mem>
0023 #endif
0024 
0025 namespace toolx {
0026 namespace Qt {
0027 
0028 class pixwin : public QWidget
0029 {
0030   typedef QWidget parent;
0031   TOOLS_SCLASS(toolx::Qt::pixwin)
0032 public:
0033   virtual void resizeEvent(QResizeEvent* a_event) {
0034   //::printf("debug : toolx::Qt::pixwin::resizeEvent : %d, %d\n",a_event->size().width(),a_event->size().height());
0035     parent::resizeEvent(a_event);
0036     m_viewer.set_size(a_event->size().width(),a_event->size().height());
0037   }
0038   virtual void paintEvent(QPaintEvent* a_event) {
0039     parent::paintEvent(a_event);
0040     if(!m_viewer.render(tools::sg::zb_viewer::get_rgbas,false)) return;  //rgbas because Qt wants an image 32 bits aligned.
0041   //static size_t s_count = 0;::printf("debug : toolx::Qt::pixwin::paintEvent %d %d : %lu\n",parent::m_ww,parent::m_wh,s_count);s_count++;
0042     QImage image(tools::vec_data(m_viewer.out_buffer()),m_viewer.width(),m_viewer.height(),QImage::Format_RGBA8888);
0043     QPixmap pixmap = QPixmap::fromImage(image);
0044     QPainter painter(this);
0045     painter.drawPixmap(0,0,pixmap);
0046   //parent::after_render();
0047     m_viewer.out_buffer_clear();
0048   }
0049 
0050   virtual void keyPressEvent(QKeyEvent* a_event) {
0051     if(!m_interactor) return;
0052     tools::sg::key_down_event _event(convert_key(a_event->key()));
0053     m_interactor->key_press(_event);
0054   }
0055   virtual void keyReleaseEvent(QKeyEvent* a_event) {
0056     if(!m_interactor) return;
0057     tools::sg::key_up_event _event(convert_key(a_event->key()));
0058     m_interactor->key_release(_event);
0059   }
0060   virtual void mousePressEvent(QMouseEvent* a_event) {
0061     if(!m_interactor) return;
0062 #if QT_VERSION < 0x060000
0063     tools::sg::mouse_down_event _event(a_event->x(),a_event->y());
0064 #else
0065     tools::sg::mouse_down_event _event(a_event->position().x(),a_event->position().y());
0066 #endif
0067     m_interactor->mouse_press(_event);
0068   }
0069   virtual void mouseReleaseEvent(QMouseEvent* a_event) {
0070     if(!m_interactor) return;
0071 #if QT_VERSION < 0x060000
0072     tools::sg::mouse_up_event _event(a_event->x(),a_event->y());
0073 #else
0074     tools::sg::mouse_up_event _event(a_event->position().x(),a_event->position().y());
0075 #endif
0076     m_interactor->mouse_release(_event);
0077   }
0078   virtual void mouseMoveEvent(QMouseEvent* a_event) {
0079     if(!m_interactor) return;
0080 #if QT_VERSION < 0x060000
0081     tools::sg::mouse_move_event _event(a_event->x(),a_event->y(),0,0,false);
0082 #else
0083     tools::sg::mouse_move_event _event(a_event->position().x(),a_event->position().y(),0,0,false);
0084 #endif
0085     m_interactor->mouse_move(_event);
0086   }
0087 //virtual void mouseDoubleClickEvent(QMouseEvent* a_event) {
0088 //  if(!m_interactor) return;
0089 //  tools::sg::mouse_double_click_event _event(a_event->x(),a_event->y());
0090 //  m_interactor->mouse_double_click(_event);
0091 //}
0092   virtual void wheelEvent(QWheelEvent* a_event) {
0093     if(!m_interactor) return;
0094     tools::sg::wheel_rotate_event _event(a_event->angleDelta().y());
0095     m_interactor->wheel_rotate(_event);
0096   }
0097 
0098 public:
0099   pixwin(QWidget* a_parent,tools::sg::zb_viewer& a_viewer):parent(a_parent),m_viewer(a_viewer),m_interactor(0){
0100 #ifdef TOOLS_MEM
0101     tools::mem::increment(s_class().c_str());
0102 #endif
0103   }
0104   virtual ~pixwin(){
0105 #ifdef TOOLS_MEM
0106     tools::mem::decrement(s_class().c_str());
0107 #endif
0108   }
0109 public:
0110   void set_device_interactor(tools::sg::device_interactor* a_interactor) {m_interactor = a_interactor;} //we do not have ownership.
0111 protected:
0112   tools::key_code convert_key(/*Qt::Key*/int a_key) {return a_key;}
0113 protected:
0114   tools::sg::zb_viewer& m_viewer;
0115   tools::sg::device_interactor* m_interactor;
0116 };
0117 
0118 }}
0119 
0120 
0121 #endif