gui.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <gui/gui.h>
  2. #include <ui_gui.h>
  3. #include <gui/recruitmentscene.h>
  4. #include <QDebug>
  5. GUI::GUI(QWidget *parent) :
  6. QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint),
  7. ui_(new Ui::GUI), dx_(0), dy_(0)
  8. {
  9. ui_->setupUi(this);
  10. rq_scene_ = new RecruitmentScene(ui_->main_content_); /// Инициализируем графическую сцену выбора юнитов
  11. rq_scene_->show();
  12. }
  13. GUI::~GUI()
  14. {
  15. delete ui_;
  16. }
  17. void GUI::mouseMoveEvent( QMouseEvent* e ) {
  18. if( e->buttons() | Qt::LeftButton ) {
  19. QPoint pt=mapFromGlobal(QCursor::pos());
  20. QWidget* child=childAt(pt);
  21. if (child == 0) {
  22. setGeometry(pos().x() + (pt.x() - dx_ ), pos().y() + (pt.y() - dy_ ), width(), height());
  23. return;
  24. }
  25. QString cname = child->metaObject()->className();
  26. if (cname != "QPushButton" && cname != "QComboBox"){ // отключаем перетягивание при наведение на активные элементы
  27. setGeometry(pos().x() + ( pt.x() - dx_ ), pos().y() + ( pt.y() - dy_ ), width(), height());
  28. } else {
  29. dx_ = pt.x();
  30. dy_ = pt.y();
  31. }
  32. }
  33. }
  34. void GUI::mousePressEvent( QMouseEvent* e ) {
  35. if(e->button() == Qt::LeftButton) {
  36. QPoint pt = mapFromGlobal(QCursor::pos());
  37. QWidget* child=childAt(pt);
  38. if (child == 0)
  39. return;
  40. QString cname = child->metaObject()->className();
  41. if (cname == "QPushButton" || cname == "QComboBox" || cname == "QLabel")
  42. return;
  43. dx_ = pt.x();
  44. dy_ = pt.y();
  45. setCursor( Qt::OpenHandCursor );
  46. }
  47. }
  48. void GUI::mouseReleaseEvent( QMouseEvent* e ) {
  49. if( e->button() == Qt::LeftButton ) {
  50. QPoint pt=mapFromGlobal(QCursor::pos());
  51. setCursor( Qt::ArrowCursor );
  52. dx_ = pt.x();
  53. dy_ = pt.y();
  54. }
  55. }