src/hbcore/gui/hbdevice.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    30 HbDeviceView::HbDeviceView()
    30 HbDeviceView::HbDeviceView()
    31 {
    31 {
    32 }
    32 }
    33 
    33 
    34 HbDeviceView::HbDeviceView(HbMainWindow *window, QWidget *parent) :
    34 HbDeviceView::HbDeviceView(HbMainWindow *window, QWidget *parent) :
    35 QGraphicsView(parent), mMainWindow(window), mAngle(0), mLastPos(0,0), 
    35     QGraphicsView(parent), mMainWindow(window), mAngle(0), mLastPos(0, 0),
    36 mMouseMove(false)
    36     mMouseMove(false)
    37 {
    37 {
    38     Q_UNUSED(parent);
    38     Q_UNUSED(parent);
    39 
    39 
    40     //Set background
    40     //Set background
    41     setBackgroundBrush(QBrush(QColor(0,0,0),Qt::SolidPattern/*Qt::VerPattern*/));
    41     setBackgroundBrush(QBrush(QColor(0, 0, 0), Qt::SolidPattern/*Qt::VerPattern*/));
    42     //Take scene from window
    42     //Take scene from window
    43     setScene(mMainWindow->scene());
    43     setScene(mMainWindow->scene());
    44 
    44 
    45     //Get real values from device profile
    45     //Get real values from device profile
    46     HbDeviceProfile profile = HbDeviceProfile::profile(mMainWindow);
    46     HbDeviceProfile profile = HbDeviceProfile::profile(mMainWindow);
    47     qreal x = mMainWindow->rect().x();
    47     qreal x = mMainWindow->rect().x();
    48     qreal y = mMainWindow->rect().y();
    48     qreal y = mMainWindow->rect().y();
    49     int h = profile.logicalSize().height();
    49     int h = profile.logicalSize().height();
    50     int w = profile.logicalSize().width();
    50     int w = profile.logicalSize().width();
    51     
    51 
    52     //Centralize
    52     //Centralize
    53     setSceneRect(x, y, w, h);
    53     setSceneRect(x, y, w, h);
    54 
    54 
    55     setDragMode(QGraphicsView::NoDrag/*QGraphicsView::ScrollHandDrag*/);
    55     setDragMode(QGraphicsView::NoDrag/*QGraphicsView::ScrollHandDrag*/);
    56     connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation)));    
    56     connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation)));
    57 }
    57 }
    58 
    58 
    59 HbDeviceView::~HbDeviceView()
    59 HbDeviceView::~HbDeviceView()
    60 {
    60 {
    61 }
    61 }
    62 
    62 
    63 void HbDeviceView::rotateDevice(int angle)
    63 void HbDeviceView::rotateDevice(int angle)
    64 {
    64 {
    65     //Store angle and block turning more than 90 or -90 degrees
    65     //Store angle and block turning more than 90 or -90 degrees
    66     mAngle = mAngle+angle;
    66     mAngle = mAngle + angle;
    67  if ( mAngle < -90 || mAngle > 90 ){
    67     if (mAngle < -90 || mAngle > 90) {
    68         if (mAngle < -90) {
    68         if (mAngle < -90) {
    69             mAngle = -90;
    69             mAngle = -90;
    70         } else {
    70         } else {
    71  mAngle = 90;
    71             mAngle = 90;
    72         }
    72         }
    73         return;
    73         return;
    74     }
    74     }
    75 
    75 
    76     rotate(angle);
    76     rotate(angle);
    77 
    77 
    78  // For special purpose, if needed..
    78 // For special purpose, if needed..
    79         if (mAngle == 0) {
    79     if (mAngle == 0) {
    80         }else if (mAngle == 90) {
    80     } else if (mAngle == 90) {
    81         }else if (mAngle == -90) {
    81     } else if (mAngle == -90) {
    82     }
    82     }
    83 }
    83 }
    84 
    84 
    85 void HbDeviceView::orientationChanged(Qt::Orientation orientation)
    85 void HbDeviceView::orientationChanged(Qt::Orientation orientation)
    86 {
    86 {
    90     int h = profile.logicalSize().height();
    90     int h = profile.logicalSize().height();
    91     int w = profile.logicalSize().width();
    91     int w = profile.logicalSize().width();
    92 
    92 
    93     //This is needed to centralize mMainWindow
    93     //This is needed to centralize mMainWindow
    94     setSceneRect(0, 0, w, h);
    94     setSceneRect(0, 0, w, h);
    95     if(!mMouseMove) {
    95     if (!mMouseMove) {
    96         resize(w+5, h+5);
    96         resize(w + 5, h + 5);
    97     }
    97     }
    98 
    98 
    99 }
    99 }
   100 
   100 
   101 //Remove black "frames"
   101 //Remove black "frames"
   102 void HbDeviceView::compressDevice()
   102 void HbDeviceView::compressDevice()
   103 {
   103 {
   104     if(mAngle <0 ) {
   104     if (mAngle < 0) {
   105         rotate(+(-mAngle)); 
   105         rotate(+(-mAngle));
   106         mAngle = 0;
   106         mAngle = 0;
   107     } else {
   107     } else {
   108  rotate(-(+mAngle));
   108         rotate(-(+mAngle));
   109  mAngle = 0;
   109         mAngle = 0;
   110     }
   110     }
   111 
   111 
   112     HbDeviceProfile profile = HbDeviceProfile::profile(mMainWindow);
   112     HbDeviceProfile profile = HbDeviceProfile::profile(mMainWindow);
   113     int h = profile.logicalSize().height();
   113     int h = profile.logicalSize().height();
   114     int w = profile.logicalSize().width();
   114     int w = profile.logicalSize().width();
   115 
   115 
   116     setSceneRect(0, 0, w, h);
   116     setSceneRect(0, 0, w, h);
   117     resize(w+5, h+5);
   117     resize(w + 5, h + 5);
   118 }
   118 }
   119 
   119 
   120 //Catch mouse move event and rotate this view
   120 //Catch mouse move event and rotate this view
   121 void HbDeviceView::mouseMoveEvent(QMouseEvent *event)
   121 void HbDeviceView::mouseMoveEvent(QMouseEvent *event)
   122 {	
   122 {
   123     if (!mMouseMove || itemAt(event->pos())) {
   123     if (!mMouseMove || itemAt(event->pos())) {
   124         return;
   124         return;
   125      }
   125     }
   126      if ((event->buttons() & Qt::LeftButton)) {
   126     if ((event->buttons() & Qt::LeftButton)) {
   127         if (event->pos().x() < mLastPos.x()) {
   127         if (event->pos().x() < mLastPos.x()) {
   128             rotateDevice(-10);
   128             rotateDevice(-10);
   129         }else if (event->pos().x() > mLastPos.x()) {
   129         } else if (event->pos().x() > mLastPos.x()) {
   130             rotateDevice(10);
   130             rotateDevice(10);
   131         }
   131         }
   132     mLastPos = event->pos();
   132         mLastPos = event->pos();
   133     }
   133     }
   134 }
   134 }
   135 
   135 
   136 void HbDeviceView::keyPressEvent(QKeyEvent *event)
   136 void HbDeviceView::keyPressEvent(QKeyEvent *event)
   137 {
   137 {
   138     //If "Ctrl+D" is pressed, enable or disable rotate
   138     //If "Ctrl+D" is pressed, enable or disable rotate
   139     if(event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_D )
   139     if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_D) {
   140     {
   140         if (!mMouseMove) {
   141         if(!mMouseMove) {
       
   142             mMouseMove = true;
   141             mMouseMove = true;
   143             enableDevice(true);
   142             enableDevice(true);
   144         } else {
   143         } else {
   145             mMouseMove = false;
   144             mMouseMove = false;
   146             enableDevice(false);
   145             enableDevice(false);
   148     }
   147     }
   149 }
   148 }
   150 
   149 
   151 void HbDeviceView::enableDevice(bool enable)
   150 void HbDeviceView::enableDevice(bool enable)
   152 {
   151 {
   153     if(enable) {
   152     if (enable) {
   154         resize(900, 900);
   153         resize(900, 900);
   155     } else {
   154     } else {
   156         compressDevice();
   155         compressDevice();
   157     }
   156     }
   158 }
   157 }