Skip to content

Commit

Permalink
Fixed black flash when setNight()
Browse files Browse the repository at this point in the history
Do not change both palette and stylesheet, creates conflicts
  • Loading branch information
alexbourgeois committed Nov 26, 2017
1 parent cd167b2 commit b03ff87
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void Bucket::InitializeClip() {

ui->openExplorerButton->setStyleSheet(QString("background-color: rgba(255, 255, 255, 255);"));
//Set working path
workingDirectory.setPath(QDir::currentPath() + "/");
workingDirectory.setPath("D:/Content/");//QDir::currentPath() + "/");
ui->lineEdit->setText(workingDirectory.absolutePath() + "/");
UpdateVisibleFiles();
}
Expand Down
48 changes: 22 additions & 26 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ MainWindow::MainWindow(QWidget *parent) :

HideTrash();

dayNightAnimation = new QPropertyAnimation(this, "color");
animationHasAValue = false;
backgroundAlpha = 0;
SetDay();
trashWidget->setVisible(true);

Expand Down Expand Up @@ -89,6 +88,7 @@ void MainWindow::InitializeWindow()
flags |= Qt::WindowStaysOnTopHint;
flags |= Qt::X11BypassWindowManagerHint;
this->setWindowFlags(flags);
this->setAttribute(Qt::WA_TranslucentBackground);



Expand Down Expand Up @@ -173,13 +173,15 @@ void MainWindow::WarnNodesFileDownloaded() {
void MainWindow::NodeMoving(NodeWidget* node) {
if(!trashVisible) {
ShowTrash();
qDebug() << "Node moving ...";
SetNight();
}
}

void MainWindow::NodeMoved(NodeWidget* node) {
HideTrash();
SetDay();
qDebug() << "Node moved !";

bool destroyed = false;
int i=0;
Expand Down Expand Up @@ -215,7 +217,7 @@ void MainWindow::ShowTrash() {
animation->setEndValue(QPoint(x, y));
animation->setEasingCurve(QEasingCurve::OutExpo);

animation->start();
animation->start(QAbstractAnimation::DeleteWhenStopped);
trashVisible = true;
}

Expand All @@ -231,45 +233,39 @@ void MainWindow::HideTrash() {
animation->setEasingCurve(QEasingCurve::InExpo);
//connect(animation, SIGNAL(finished()), this, SLOT(MoveToNode()));

animation->start();
animation->start(QAbstractAnimation::DeleteWhenStopped);
trashVisible = false;
}

void MainWindow::SetNight() {
//this->setAttribute(Qt::WA_TranslucentBackground, false);

// backgroundAlpha = 20;
// this->setStyleSheet("background-color:rgba(0,0,0,50);");

QPropertyAnimation *dayNightAnimation = new QPropertyAnimation(this, "color");
QPropertyAnimation *dayNightAnimation = new QPropertyAnimation(this, "backgroundAlpha");
dayNightAnimation->setDuration(250);
dayNightAnimation->setStartValue(color());
dayNightAnimation->setEndValue(QColor(0, 0, 0, 50));
dayNightAnimation->start();
this->show();
dayNightAnimation->setStartValue(backgroundAlpha);
dayNightAnimation->setEndValue(75);
dayNightAnimation->setDuration(500);
dayNightAnimation->setEasingCurve(QEasingCurve::OutExpo);
dayNightAnimation->start(QAbstractAnimation::DeleteWhenStopped);

qDebug() << "Set Night";
}

void MainWindow::SetDay() {
this->setAttribute(Qt::WA_TranslucentBackground);
// backgroundAlpha = 1;
// this->setStyleSheet("background-color:rgba(0,0,0,0);");


QPropertyAnimation *animation = new QPropertyAnimation(this, "color");
QPropertyAnimation *animation = new QPropertyAnimation(this, "backgroundAlpha");
animation->setDuration(250);
animation->setStartValue(color());
animation->setEndValue(QColor(0, 0, 0, 0));
animation->start();
animationHasAValue = true;
animation->setStartValue(backgroundAlpha);
animation->setEndValue(0);
animation->setEasingCurve(QEasingCurve::InExpo);
animation->start(QAbstractAnimation::DeleteWhenStopped);

this->show();
qDebug() << "Set Day";
}


void MainWindow::paintEvent(QPaintEvent *event) {

QColor backgroundColor = QColor(0,0,0,0);
backgroundColor.setAlpha(backgroundAlpha);
QPainter customPainter(this);
customPainter.fillRect(rect(),backgroundColor);
// QColor backgroundColor = palette().light().color();
// backgroundColor.setAlpha(backgroundAlpha);
// QPainter customPainter(this);
Expand Down
22 changes: 14 additions & 8 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MainWindow;
class MainWindow : public QMainWindow
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor)
Q_PROPERTY(int backgroundAlpha READ getBackgroundAlpha WRITE setBackgroundAlpha)

public:
explicit MainWindow(QWidget *parent = 0);
Expand All @@ -43,11 +43,19 @@ class MainWindow : public QMainWindow
void dropEvent(QDropEvent *event);
void leaveEvent(QEvent* e);

void setColor (QColor color){
setStyleSheet(QString("background-color: rgba(%1, %2, %3, %4);").arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha()));
int getBackgroundAlpha() {
return backgroundAlpha;
}
QColor color(){
return QWidget::palette().color(QWidget::backgroundRole());

void setBackgroundAlpha(int value) {
backgroundAlpha = value;
QPalette palette;
palette.setBrush(QPalette::Background, QColor(0,0,0,backgroundAlpha));
this->setAutoFillBackground(true);
setPalette(palette);

repaint();
this->show();
}

signals:
Expand All @@ -67,7 +75,7 @@ public slots:
public:
int width;
int height;
int backgroundAlpha;
int backgroundAlpha = 255;
bool trashVisible;
bool UIVisible;

Expand All @@ -76,8 +84,6 @@ public slots:
private:
void InitializeWindow();

QPropertyAnimation* dayNightAnimation;
bool animationHasAValue;
QThread workerThread;
QPoint dragPosition;
DownloadManager *manager;
Expand Down
3 changes: 3 additions & 0 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<widget class="QWidget" name="centralWidget"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
Expand Down
5 changes: 4 additions & 1 deletion node.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
<height>300</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>NodeWidget</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
<bool>false</bool>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
Expand Down
18 changes: 5 additions & 13 deletions nodewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ NodeWidget::NodeWidget(Node* node,QWidget *parent, int size, NodeSettings settin
isBucketOpened = false;
bucket = new Bucket(settings, this->nodeDrawer);
bucket->setStyleSheet(QString("background-color: rgba(255, 255, 255, 0);"));
bucket->setVisible(true);
bucket->setVisible(false);
bucket->move(BottomLeft());
//ToggleBucket();

Expand Down Expand Up @@ -172,18 +172,6 @@ void NodeWidget::DockNode() {
animation->start();
}

void NodeWidget::CreatePainter()
{
/*p = new QPainter(this);
b = new QRadialGradient();
b->setColorAt(0.0, Qt::white);
b->setColorAt(0.2, Qt::green);
b->setColorAt(1.0, Qt::black);
p->setBrush(*b);
p->setRenderHint(QPainter::Antialiasing, true);
p->setPen(QPen(Qt::green, 0));*/
}

void NodeWidget::MoveTo(int x, int y)
{
QPoint target(x, y);
Expand Down Expand Up @@ -235,6 +223,10 @@ QString NodeWidget::GetName()

void NodeWidget::paintEvent(QPaintEvent *event)
{
QColor backgroundColor = QColor(0,0,0);//palette().dark().color();
backgroundColor.setAlpha(0);
QPainter customPainter(this);
customPainter.fillRect(rect(),backgroundColor);
this->show();
// QRadialGradient brush(rect().center().x(), rect().center().y(), _radius);
// brush.setColorAt(0.0, _color);
Expand Down
3 changes: 1 addition & 2 deletions nodewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class NodeWidget : public QWidget
public:
NodeWidget(Node* node, QWidget *parent, int size, NodeSettings settings);
~NodeWidget();
void CreatePainter();
virtual void paintEvent(QPaintEvent*);

virtual void paintEvent(QPaintEvent*);
virtual void enterEvent(QEvent* e);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
Expand Down

0 comments on commit b03ff87

Please sign in to comment.