diff --git a/gui/davis_gui.cpp b/gui/davis_gui.cpp index 687802f..aaaa0d6 100644 --- a/gui/davis_gui.cpp +++ b/gui/davis_gui.cpp @@ -34,6 +34,7 @@ using std::string; using std::vector; using namespace dvs; const int ANIMATION_DURATION = 300; +const double OPACITY_IF_NOT_ACTIVE = 0.5; DavisGUI::DavisGUI(QWidget* parent) : QMainWindow(parent) @@ -191,6 +192,9 @@ DavisGUI::DavisGUI(QWidget* parent) settingsFilePath = "settings.json"; QJsonObject settings = loadSettings(settingsFilePath); applySettings(settings); + animationOpacity = new QPropertyAnimation(this, "windowOpacity"); + animationOpacity->setDuration(ANIMATION_DURATION); // Длительность анимации в миллисекундах + animationOpacity->setEasingCurve(QEasingCurve::InOutQuad); // Задаем плавность кривой } DavisGUI::~DavisGUI() { @@ -513,7 +517,7 @@ bool DavisGUI::mayBeShowBIN(const QString& path) { void DavisGUI::setMaxStyleWindow(int animDuration) { m_isMinStyleWindow = false; hideElementsDuringResize(); - + setWindowOpacity(1); QPropertyAnimation* animationFrame = new QPropertyAnimation(ui->frame_panel, "geometry"); animationFrame->setEasingCurve(QEasingCurve::InOutQuad); animationFrame->setDuration(animDuration); @@ -555,7 +559,7 @@ void DavisGUI::setMaxStyleWindow(int animDuration) { void DavisGUI::setMinStyleWindow(int animDuration) { m_isMinStyleWindow = true; hideElementsDuringResize(); - + setWindowOpacity(OPACITY_IF_NOT_ACTIVE); QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry"); animation->setDuration(animDuration); animation->setEasingCurve(QEasingCurve::InOutQuad); @@ -905,12 +909,19 @@ void DavisGUI::dragEnterEvent(QDragEnterEvent* event) { group->start(QAbstractAnimation::DeleteWhenStopped); - + setFullOpacity(); if (event->mimeData()->hasUrls()) { event->acceptProposedAction(); } else { qDebug() << "not drop"; } + +} + +void DavisGUI::dragLeaveEvent(QDragLeaveEvent* event) { + if (m_isMinStyleWindow) { + setSemiOpacity(); + } } @@ -1065,3 +1076,31 @@ void DavisGUI::keyPressEvent(QKeyEvent* event) { } } +void DavisGUI::setFullOpacity() { + if (m_isMinStyleWindow) { + animationOpacity->stop(); + animationOpacity->setStartValue(windowOpacity()); + animationOpacity->setEndValue(1.0); // Непрозрачное окно + animationOpacity->start(); + } +} + +void DavisGUI::enterEvent(QEvent* event) { + setFullOpacity(); + QMainWindow::enterEvent(event); +} + +void DavisGUI::setSemiOpacity() { + if (m_isMinStyleWindow) { + animationOpacity->stop(); + animationOpacity->setStartValue(windowOpacity()); + animationOpacity->setEndValue(OPACITY_IF_NOT_ACTIVE); // Полупрозрачное окно + animationOpacity->start(); + } +} + +void DavisGUI::leaveEvent(QEvent* event) { + setSemiOpacity(); + QMainWindow::leaveEvent(event); +} + diff --git a/gui/davis_gui.h b/gui/davis_gui.h index 0141f5b..4ff8d75 100644 --- a/gui/davis_gui.h +++ b/gui/davis_gui.h @@ -34,11 +34,14 @@ class DavisGUI : public QMainWindow { protected: void dragEnterEvent(QDragEnterEvent* event) override; + void dragLeaveEvent(QDragLeaveEvent* event) override; void dropEvent(QDropEvent* event) override; void paintEvent(QPaintEvent* event) override; void mousePressEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; void keyPressEvent(QKeyEvent* event) override; + void enterEvent(QEvent* event) override; + void leaveEvent(QEvent* event) override; private: void setMaxStyleWindow(int animDuration); @@ -70,6 +73,8 @@ class DavisGUI : public QMainWindow { QStringList getLinesFromFile(const QString& pathToFile); bool mayBeShowBIN(const QString& path); + void setFullOpacity(); + void setSemiOpacity(); private slots: void showAboutWindow(); @@ -95,6 +100,6 @@ class DavisGUI : public QMainWindow { bool m_isUseCustomSkins; Skins m_skin; bool m_isFitGraphToWindow; - + QPropertyAnimation* animationOpacity; }; #endif // DAVISGUI_H