GUI.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <gui/GUI.h>
  2. #include <ui_GUI.h>
  3. #include <QDebug>
  4. GUI::GUI(QWidget *parent) :
  5. QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint),
  6. ui_(new Ui::GUI), dx_(-100000), dy_(-100000)
  7. {
  8. ui_->setupUi(this);
  9. setWindowTitle("Супер-мега-клёвая-игрушка-название-которой-мы-ещё-не-придумали");
  10. }
  11. GUI::~GUI()
  12. {
  13. delete ui_;
  14. }
  15. QWidget* GUI::mainContentScene() {
  16. return ui_->main_content_;
  17. }
  18. void GUI::mouseMoveEvent( QMouseEvent* e ) {
  19. if( e->buttons() | Qt::LeftButton ) {
  20. QPoint pt=mapFromGlobal(QCursor::pos());
  21. if (dx_ != -100000 && dy_ != -100000)
  22. setGeometry(pos().x() + ( pt.x() - dx_ ), pos().y() + ( pt.y() - dy_ ), width(), height());
  23. }
  24. }
  25. void GUI::mousePressEvent( QMouseEvent* e ) {
  26. if(e->button() == Qt::LeftButton) {
  27. QPoint pt = mapFromGlobal(QCursor::pos());
  28. QWidget* child=childAt(pt);
  29. if (child == 0) {
  30. dx_ = -100000;
  31. dy_ = -100000;
  32. return;
  33. }
  34. QString cname = child->objectName();
  35. if (cname == "window_top_border_" || cname == "window_bottom_border_"
  36. || cname == "window_topleft_border_" || cname == "window_topright_border_"
  37. || cname == "window_right_border_" || cname == "window_left_border_"
  38. || cname == "window_botright_border_" || cname == "window_botleft_border_") {
  39. dx_ = pt.x();
  40. dy_ = pt.y();
  41. } else {
  42. dx_ = -100000;
  43. dy_ = -100000;
  44. }
  45. }
  46. }
  47. void GUI::mouseReleaseEvent( QMouseEvent* e ) {
  48. if( e->button() == Qt::LeftButton ) {
  49. dx_ = -100000;
  50. dy_ = -100000;
  51. }
  52. }