Skip to content

adaptive transparency in GUI #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions gui/davis_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}


Expand Down Expand Up @@ -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);
}

7 changes: 6 additions & 1 deletion gui/davis_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -95,6 +100,6 @@ class DavisGUI : public QMainWindow {
bool m_isUseCustomSkins;
Skins m_skin;
bool m_isFitGraphToWindow;

QPropertyAnimation* animationOpacity;
};
#endif // DAVISGUI_H