Skip to content

Commit 07df5a7

Browse files
authored
adaptive transparency in GUI (#160)
1 parent 206b981 commit 07df5a7

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

gui/davis_gui.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ using std::string;
3434
using std::vector;
3535
using namespace dvs;
3636
const int ANIMATION_DURATION = 300;
37+
const double OPACITY_IF_NOT_ACTIVE = 0.5;
3738

3839
DavisGUI::DavisGUI(QWidget* parent)
3940
: QMainWindow(parent)
@@ -191,6 +192,9 @@ DavisGUI::DavisGUI(QWidget* parent)
191192
settingsFilePath = "settings.json";
192193
QJsonObject settings = loadSettings(settingsFilePath);
193194
applySettings(settings);
195+
animationOpacity = new QPropertyAnimation(this, "windowOpacity");
196+
animationOpacity->setDuration(ANIMATION_DURATION); // Длительность анимации в миллисекундах
197+
animationOpacity->setEasingCurve(QEasingCurve::InOutQuad); // Задаем плавность кривой
194198
}
195199

196200
DavisGUI::~DavisGUI() {
@@ -513,7 +517,7 @@ bool DavisGUI::mayBeShowBIN(const QString& path) {
513517
void DavisGUI::setMaxStyleWindow(int animDuration) {
514518
m_isMinStyleWindow = false;
515519
hideElementsDuringResize();
516-
520+
setWindowOpacity(1);
517521
QPropertyAnimation* animationFrame = new QPropertyAnimation(ui->frame_panel, "geometry");
518522
animationFrame->setEasingCurve(QEasingCurve::InOutQuad);
519523
animationFrame->setDuration(animDuration);
@@ -555,7 +559,7 @@ void DavisGUI::setMaxStyleWindow(int animDuration) {
555559
void DavisGUI::setMinStyleWindow(int animDuration) {
556560
m_isMinStyleWindow = true;
557561
hideElementsDuringResize();
558-
562+
setWindowOpacity(OPACITY_IF_NOT_ACTIVE);
559563
QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry");
560564
animation->setDuration(animDuration);
561565
animation->setEasingCurve(QEasingCurve::InOutQuad);
@@ -905,12 +909,19 @@ void DavisGUI::dragEnterEvent(QDragEnterEvent* event) {
905909

906910
group->start(QAbstractAnimation::DeleteWhenStopped);
907911

908-
912+
setFullOpacity();
909913
if (event->mimeData()->hasUrls()) {
910914
event->acceptProposedAction();
911915
} else {
912916
qDebug() << "not drop";
913917
}
918+
919+
}
920+
921+
void DavisGUI::dragLeaveEvent(QDragLeaveEvent* event) {
922+
if (m_isMinStyleWindow) {
923+
setSemiOpacity();
924+
}
914925
}
915926

916927

@@ -1065,3 +1076,31 @@ void DavisGUI::keyPressEvent(QKeyEvent* event) {
10651076
}
10661077
}
10671078

1079+
void DavisGUI::setFullOpacity() {
1080+
if (m_isMinStyleWindow) {
1081+
animationOpacity->stop();
1082+
animationOpacity->setStartValue(windowOpacity());
1083+
animationOpacity->setEndValue(1.0); // Непрозрачное окно
1084+
animationOpacity->start();
1085+
}
1086+
}
1087+
1088+
void DavisGUI::enterEvent(QEvent* event) {
1089+
setFullOpacity();
1090+
QMainWindow::enterEvent(event);
1091+
}
1092+
1093+
void DavisGUI::setSemiOpacity() {
1094+
if (m_isMinStyleWindow) {
1095+
animationOpacity->stop();
1096+
animationOpacity->setStartValue(windowOpacity());
1097+
animationOpacity->setEndValue(OPACITY_IF_NOT_ACTIVE); // Полупрозрачное окно
1098+
animationOpacity->start();
1099+
}
1100+
}
1101+
1102+
void DavisGUI::leaveEvent(QEvent* event) {
1103+
setSemiOpacity();
1104+
QMainWindow::leaveEvent(event);
1105+
}
1106+

gui/davis_gui.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ class DavisGUI : public QMainWindow {
3434

3535
protected:
3636
void dragEnterEvent(QDragEnterEvent* event) override;
37+
void dragLeaveEvent(QDragLeaveEvent* event) override;
3738
void dropEvent(QDropEvent* event) override;
3839
void paintEvent(QPaintEvent* event) override;
3940
void mousePressEvent(QMouseEvent* event) override;
4041
void mouseMoveEvent(QMouseEvent* event) override;
4142
void keyPressEvent(QKeyEvent* event) override;
43+
void enterEvent(QEvent* event) override;
44+
void leaveEvent(QEvent* event) override;
4245

4346
private:
4447
void setMaxStyleWindow(int animDuration);
@@ -70,6 +73,8 @@ class DavisGUI : public QMainWindow {
7073

7174
QStringList getLinesFromFile(const QString& pathToFile);
7275
bool mayBeShowBIN(const QString& path);
76+
void setFullOpacity();
77+
void setSemiOpacity();
7378

7479
private slots:
7580
void showAboutWindow();
@@ -95,6 +100,6 @@ class DavisGUI : public QMainWindow {
95100
bool m_isUseCustomSkins;
96101
Skins m_skin;
97102
bool m_isFitGraphToWindow;
98-
103+
QPropertyAnimation* animationOpacity;
99104
};
100105
#endif // DAVISGUI_H

0 commit comments

Comments
 (0)