added basic new user popup

This commit is contained in:
fourtf
2018-06-06 10:46:23 +02:00
parent f542a5b999
commit 86e4a669ad
21 changed files with 365 additions and 85 deletions
+64 -49
View File
@@ -10,28 +10,37 @@ namespace widgets {
RippleEffectButton::RippleEffectButton(BaseWidget *parent)
: BaseWidget(parent)
, pixmap(nullptr)
{
connect(&effectTimer, &QTimer::timeout, this, &RippleEffectButton::onMouseEffectTimeout);
connect(&effectTimer_, &QTimer::timeout, this, &RippleEffectButton::onMouseEffectTimeout);
this->effectTimer.setInterval(20);
this->effectTimer.start();
this->effectTimer_.setInterval(20);
this->effectTimer_.start();
}
void RippleEffectButton::setMouseEffectColor(boost::optional<QColor> color)
{
this->mouseEffectColor = color;
this->mouseEffectColor_ = color;
}
void RippleEffectButton::setPixmap(const QPixmap *_pixmap)
void RippleEffectButton::setPixmap(const QPixmap &_pixmap)
{
this->pixmap = const_cast<QPixmap *>(_pixmap);
this->pixmap_ = _pixmap;
this->update();
}
const QPixmap *RippleEffectButton::getPixmap() const
const QPixmap &RippleEffectButton::getPixmap() const
{
return this->pixmap;
return this->pixmap_;
}
void RippleEffectButton::setBorderColor(const QColor &color)
{
this->borderColor_ = color;
}
const QColor &RippleEffectButton::getBorderColor() const
{
return this->borderColor_;
}
void RippleEffectButton::paintEvent(QPaintEvent *)
@@ -42,16 +51,22 @@ void RippleEffectButton::paintEvent(QPaintEvent *)
this->fancyPaint(painter);
if (this->pixmap != nullptr) {
if (!this->pixmap_.isNull()) {
QRect rect = this->rect();
int xD = 6 * this->getScale();
int s = int(6 * this->getScale());
rect.moveLeft(xD);
rect.setRight(rect.right() - xD - xD);
rect.moveTop(xD);
rect.setBottom(rect.bottom() - xD - xD);
rect.moveLeft(s);
rect.setRight(rect.right() - s - s);
rect.moveTop(s);
rect.setBottom(rect.bottom() - s - s);
painter.drawPixmap(rect, *this->pixmap);
painter.drawPixmap(rect, this->pixmap_);
}
if (this->borderColor_.isValid()) {
painter.setRenderHint(QPainter::Antialiasing, false);
painter.setPen(this->borderColor_);
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
}
}
@@ -61,33 +76,33 @@ void RippleEffectButton::fancyPaint(QPainter &painter)
painter.setRenderHint(QPainter::Antialiasing);
QColor c;
if (this->mouseEffectColor) {
c = this->mouseEffectColor.get();
if (this->mouseEffectColor_) {
c = this->mouseEffectColor_.get();
} else {
c = this->themeManager->isLightTheme() ? QColor(0, 0, 0) : QColor(255, 255, 255);
}
if (this->hoverMultiplier > 0) {
QRadialGradient gradient(mousePos.x(), mousePos.y(), 50, mousePos.x(), mousePos.y());
if (this->hoverMultiplier_ > 0) {
QRadialGradient gradient(mousePos_.x(), mousePos_.y(), 50, mousePos_.x(), mousePos_.y());
gradient.setColorAt(
0, QColor(c.red(), c.green(), c.blue(), (int)(24 * this->hoverMultiplier)));
gradient.setColorAt(
1, QColor(c.red(), c.green(), c.blue(), (int)(12 * this->hoverMultiplier)));
gradient.setColorAt(0,
QColor(c.red(), c.green(), c.blue(), int(24 * this->hoverMultiplier_)));
gradient.setColorAt(1,
QColor(c.red(), c.green(), c.blue(), int(12 * this->hoverMultiplier_)));
painter.fillRect(this->rect(), gradient);
}
for (auto effect : this->clickEffects) {
for (auto effect : this->clickEffects_) {
QRadialGradient gradient(effect.position.x(), effect.position.y(),
effect.progress * (float)width() * 2, effect.position.x(),
effect.progress * float(width()) * 2, effect.position.x(),
effect.position.y());
gradient.setColorAt(
0, QColor(c.red(), c.green(), c.blue(), (int)((1 - effect.progress) * 95)));
gradient.setColorAt(
0.9999, QColor(c.red(), c.green(), c.blue(), (int)((1 - effect.progress) * 95)));
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), (int)(0)));
gradient.setColorAt(0,
QColor(c.red(), c.green(), c.blue(), int((1 - effect.progress) * 95)));
gradient.setColorAt(0.9999,
QColor(c.red(), c.green(), c.blue(), int((1 - effect.progress) * 95)));
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), int(0)));
painter.fillRect(this->rect(), gradient);
}
@@ -95,12 +110,12 @@ void RippleEffectButton::fancyPaint(QPainter &painter)
void RippleEffectButton::enterEvent(QEvent *)
{
this->mouseOver = true;
this->mouseOver_ = true;
}
void RippleEffectButton::leaveEvent(QEvent *)
{
this->mouseOver = false;
this->mouseOver_ = false;
}
void RippleEffectButton::mousePressEvent(QMouseEvent *event)
@@ -109,9 +124,9 @@ void RippleEffectButton::mousePressEvent(QMouseEvent *event)
return;
}
this->clickEffects.push_back(ClickEffect(event->pos()));
this->clickEffects_.push_back(ClickEffect(event->pos()));
this->mouseDown = true;
this->mouseDown_ = true;
}
void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event)
@@ -120,7 +135,7 @@ void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event)
return;
}
this->mouseDown = false;
this->mouseDown_ = false;
if (this->rect().contains(event->pos())) {
emit clicked();
@@ -129,38 +144,38 @@ void RippleEffectButton::mouseReleaseEvent(QMouseEvent *event)
void RippleEffectButton::mouseMoveEvent(QMouseEvent *event)
{
this->mousePos = event->pos();
this->mousePos_ = event->pos();
}
void RippleEffectButton::onMouseEffectTimeout()
{
bool performUpdate = false;
if (selected) {
if (this->hoverMultiplier != 0) {
this->hoverMultiplier = std::max(0.0, this->hoverMultiplier - 0.1);
if (selected_) {
if (this->hoverMultiplier_ != 0) {
this->hoverMultiplier_ = std::max(0.0, this->hoverMultiplier_ - 0.1);
performUpdate = true;
}
} else if (mouseOver) {
if (this->hoverMultiplier != 1) {
this->hoverMultiplier = std::min(1.0, this->hoverMultiplier + 0.5);
} else if (mouseOver_) {
if (this->hoverMultiplier_ != 1) {
this->hoverMultiplier_ = std::min(1.0, this->hoverMultiplier_ + 0.5);
performUpdate = true;
}
} else {
if (this->hoverMultiplier != 0) {
this->hoverMultiplier = std::max(0.0, this->hoverMultiplier - 0.3);
if (this->hoverMultiplier_ != 0) {
this->hoverMultiplier_ = std::max(0.0, this->hoverMultiplier_ - 0.3);
performUpdate = true;
}
}
if (this->clickEffects.size() != 0) {
if (this->clickEffects_.size() != 0) {
performUpdate = true;
for (auto it = this->clickEffects.begin(); it != this->clickEffects.end();) {
(*it).progress += mouseDown ? 0.02 : 0.07;
for (auto it = this->clickEffects_.begin(); it != this->clickEffects_.end();) {
(*it).progress += mouseDown_ ? 0.02 : 0.07;
if ((*it).progress >= 1.0) {
it = this->clickEffects.erase(it);
it = this->clickEffects_.erase(it);
} else {
it++;
}