mainwindow.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QBitmap>
  4. #include <QMouseEvent>
  5. #include <QMessageBox>
  6. #include <QDesktopWidget>
  7. #include <QDebug>
  8. MainWindow::MainWindow(QWidget *parent) :
  9. QMainWindow(parent, Qt::Window | Qt::FramelessWindowHint),
  10. ui(new Ui::MainWindow), menuHoverWidget(nullptr), menuHoverWidgetAnimation(nullptr)
  11. {
  12. ui->setupUi(this);
  13. QPixmap maskPix;
  14. maskPix.fill(":/assets/bg1.png");
  15. maskPix = maskPix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  16. setMask(maskPix.mask());
  17. menuHoverWidget = new QWidget(ui->menu_widget);
  18. menuHoverWidget->setStyleSheet("background-color: rgba(55, 37, 31, 250);");
  19. menuHoverWidget->resize(0, 0);
  20. connect(ui->menuentry_1, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
  21. connect(ui->menuentry_2, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
  22. connect(ui->menuentry_3, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
  23. connect(ui->menuentry_4, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
  24. connect(ui->menuentry_5, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
  25. connect(ui->menuentry_6, &ClickableLabel::active_label_changed, this, &MainWindow::on_active_menuentry_changed);
  26. }
  27. void MainWindow::mousePressEvent(QMouseEvent *event)
  28. {
  29. if (event->button() == Qt::LeftButton) {
  30. dragPosition = event->globalPos() - frameGeometry().topLeft();
  31. event->accept();
  32. }
  33. }
  34. void MainWindow::mouseMoveEvent(QMouseEvent *event)
  35. {
  36. if (event->buttons() & Qt::LeftButton) {
  37. move(event->globalPos() - dragPosition);
  38. event->accept();
  39. }
  40. }
  41. void MainWindow::resizeEvent(QResizeEvent * /* event */)
  42. {
  43. QPixmap maskPix(":/assets/bg1.png");
  44. maskPix = maskPix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  45. setMask(maskPix.mask());
  46. }
  47. MainWindow::~MainWindow()
  48. {
  49. delete ui;
  50. }
  51. void MainWindow::on_menuentry_1_clicked()
  52. {
  53. QMessageBox msgBox;
  54. msgBox.setIcon(QMessageBox::Information);
  55. msgBox.setText("Нажали на \"Статус\"!");
  56. msgBox.exec();
  57. }
  58. void MainWindow::on_menuentry_2_clicked()
  59. {
  60. QMessageBox msgBox;
  61. msgBox.setIcon(QMessageBox::Information);
  62. msgBox.setText("Нажали на \"Настройки\"!");
  63. msgBox.exec();
  64. }
  65. void MainWindow::on_menuentry_3_clicked()
  66. {
  67. QMessageBox msgBox;
  68. msgBox.setIcon(QMessageBox::Information);
  69. msgBox.setText("Нажали на \"Русификация\"!");
  70. msgBox.exec();
  71. }
  72. void MainWindow::on_menuentry_4_clicked()
  73. {
  74. QMessageBox msgBox;
  75. msgBox.setIcon(QMessageBox::Information);
  76. msgBox.setText("Нажали на \"Новости\"!");
  77. msgBox.exec();
  78. }
  79. void MainWindow::on_menuentry_5_clicked()
  80. {
  81. QMessageBox msgBox;
  82. msgBox.setIcon(QMessageBox::Information);
  83. msgBox.setText("Нажали на \"Помощь\"!");
  84. msgBox.exec();
  85. }
  86. void MainWindow::on_menuentry_6_clicked()
  87. {
  88. QMessageBox msgBox;
  89. msgBox.setIcon(QMessageBox::Information);
  90. msgBox.setText("Нажали на \"О нас\"!");
  91. msgBox.exec();
  92. }
  93. void MainWindow::on_active_menuentry_changed()
  94. {
  95. ClickableLabel* active_label = ClickableLabel::getActiveLabel();
  96. if (menuHoverWidget->size() == QSize(0, 0)) {
  97. menuHoverWidget->resize(active_label->size() + QSize(10, 0));
  98. menuHoverWidget->move(active_label->pos() + QPoint(-5, 0));
  99. }
  100. if (menuHoverWidgetAnimation == nullptr)
  101. menuHoverWidgetAnimation = new QPropertyAnimation(menuHoverWidget, "geometry");
  102. else
  103. menuHoverWidgetAnimation->stop();
  104. menuHoverWidgetAnimation->setDuration(200);
  105. menuHoverWidgetAnimation->setStartValue(QRect(menuHoverWidget->pos(), menuHoverWidget->size()));
  106. menuHoverWidgetAnimation->setEndValue(QRect(active_label->pos() + QPoint(-5, 0), active_label->size() + QSize(10, 0)));
  107. menuHoverWidgetAnimation->start();
  108. ui->menuentry_1->raise();
  109. ui->menuentry_2->raise();
  110. ui->menuentry_3->raise();
  111. ui->menuentry_4->raise();
  112. ui->menuentry_5->raise();
  113. ui->menuentry_6->raise();
  114. }