From 4b2ddb0bbbd21b916ee9e01d89aa4d68363b11cc Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 26 Jan 2017 05:26:21 +0100 Subject: [PATCH] added some dank tab animations --- widgets/chatwidgetview.cpp | 2 +- widgets/notebook.cpp | 11 +++++----- widgets/notebook.h | 2 +- widgets/notebooktab.cpp | 44 ++++++++++++++++++++++---------------- widgets/notebooktab.h | 14 +++++++++--- widgets/scrollbar.cpp | 14 ++++++------ widgets/scrollbar.h | 1 + 7 files changed, 53 insertions(+), 35 deletions(-) diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index 8cf3dd2f..a57864c9 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -18,7 +18,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent) , chatWidget(parent) , scrollbar(this) { - this->scrollbar.setSmallChange(2); + this->scrollbar.setSmallChange(5); QObject::connect(&Settings::getInstance(), &Settings::wordTypeMaskChanged, this, &ChatWidgetView::wordTypeMaskChanged); diff --git a/widgets/notebook.cpp b/widgets/notebook.cpp index 83e70718..ea00a75c 100644 --- a/widgets/notebook.cpp +++ b/widgets/notebook.cpp @@ -92,6 +92,7 @@ Notebook::select(NotebookPage *page) if (page != nullptr) { page->setHidden(false); page->tab->setSelected(true); + page->tab->raise(); } if (this->selectedPage != nullptr) { @@ -110,7 +111,7 @@ Notebook::tabAt(QPoint point, int &index) int i = 0; for (auto *page : pages) { - if (page->tab->geometry().contains(point)) { + if (page->tab->getDesiredRect().contains(point)) { index = i; return page; } @@ -135,7 +136,7 @@ Notebook::rearrangePage(NotebookPage *page, int index) } void -Notebook::performLayout() +Notebook::performLayout(bool animated) { int x = 48, y = 0; int tabHeight = 16; @@ -148,10 +149,10 @@ Notebook::performLayout() (i == this->pages.last() ? tabHeight : 0) + x + i->tab->width() > width()) { y += i->tab->height(); - i->tab->moveAnimated(QPoint(0, y)); + i->tab->moveAnimated(QPoint(0, y), animated); x = i->tab->width(); } else { - i->tab->moveAnimated(QPoint(x, y)); + i->tab->moveAnimated(QPoint(x, y), animated); x += i->tab->width(); } @@ -169,7 +170,7 @@ Notebook::performLayout() void Notebook::resizeEvent(QResizeEvent *) { - performLayout(); + performLayout(false); } void diff --git a/widgets/notebook.h b/widgets/notebook.h index 0fce894a..919ed0d6 100644 --- a/widgets/notebook.h +++ b/widgets/notebook.h @@ -31,7 +31,7 @@ public: return selectedPage; } - void performLayout(); + void performLayout(bool animate = true); NotebookPage *tabAt(QPoint point, int &index); void rearrangePage(NotebookPage *page, int index); diff --git a/widgets/notebooktab.cpp b/widgets/notebooktab.cpp index 8115dfcf..94222275 100644 --- a/widgets/notebooktab.cpp +++ b/widgets/notebooktab.cpp @@ -10,8 +10,9 @@ namespace widgets { NotebookTab::NotebookTab(Notebook *notebook) : QWidget(notebook) - // , posAnimation(this, "pos") - // , posAnimated(false) + , posAnimation(this, "pos") + , posAnimated(false) + , posAnimationDesired() , notebook(notebook) , text("") , selected(false) @@ -24,12 +25,17 @@ NotebookTab::NotebookTab(Notebook *notebook) this->calcSize(); this->setAcceptDrops(true); + posAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic)); + /* XXX(pajlada): Fix this QObject::connect(&Settings::getInstance().getHideTabX(), &BoolSetting::valueChanged, this, &NotebookTab::hideTabXChanged); */ + // Settings::getInstance().hideTabX.valueChanged.connect( + // boost::bind(&NotebookTab::hideTabXChanged, this)); + this->setMouseTracking(true); } @@ -53,26 +59,28 @@ NotebookTab::calcSize() } void -NotebookTab::moveAnimated(QPoint pos) +NotebookTab::moveAnimated(QPoint pos, bool animated) { - move(pos); + // move(pos); - // if (posAnimated == false) { - // move(pos); + posAnimationDesired = pos; - // posAnimated = true; - // return; - // } + if (!animated || posAnimated == false) { + move(pos); - // if (this->posAnimation.endValue() == pos) { - // return; - // } + posAnimated = true; + return; + } - // this->posAnimation.stop(); - // this->posAnimation.setDuration(50); - // this->posAnimation.setStartValue(this->pos()); - // this->posAnimation.setEndValue(pos); - // this->posAnimation.start(); + if (this->posAnimation.endValue() == pos) { + return; + } + + this->posAnimation.stop(); + this->posAnimation.setDuration(75); + this->posAnimation.setStartValue(this->pos()); + this->posAnimation.setEndValue(pos); + this->posAnimation.start(); } void @@ -184,7 +192,7 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event) this->repaint(); } - if (this->mouseDown && !this->rect().contains(event->pos())) { + if (this->mouseDown && !this->getDesiredRect().contains(event->pos())) { QPoint relPoint = this->mapToParent(event->pos()); int index; diff --git a/widgets/notebooktab.h b/widgets/notebooktab.h index c008e0d9..360495b8 100644 --- a/widgets/notebooktab.h +++ b/widgets/notebooktab.h @@ -66,7 +66,14 @@ public: repaint(); } - void moveAnimated(QPoint pos); + void moveAnimated(QPoint pos, bool animated = true); + +public: + QRect + getDesiredRect() const + { + return QRect(posAnimationDesired, this->size()); + } protected: void paintEvent(QPaintEvent *) override; @@ -81,8 +88,9 @@ protected: void mouseMoveEvent(QMouseEvent *event) override; private: - // QPropertyAnimation posAnimation; - // bool posAnimated; + QPropertyAnimation posAnimation; + bool posAnimated; + QPoint posAnimationDesired; Notebook *notebook; diff --git a/widgets/scrollbar.cpp b/widgets/scrollbar.cpp index da749f65..ffd6dc91 100644 --- a/widgets/scrollbar.cpp +++ b/widgets/scrollbar.cpp @@ -172,21 +172,21 @@ ScrollBar::mouseReleaseEvent(QMouseEvent *event) if (y < this->buttonHeight) { if (this->mouseDownIndex == 0) { - this->setValue(this->value - this->smallChange); + this->setValue(this->value - this->smallChange, true); } } else if (y < this->thumbRect.y()) { - if (this->mouseDownIndex == 0) { - this->setValue(this->value - this->smallChange); + if (this->mouseDownIndex == 1) { + this->setValue(this->value - this->smallChange, true); } } else if (this->thumbRect.contains(2, y)) { // do nothing } else if (y < height() - this->buttonHeight) { - if (this->mouseDownIndex == 0) { - this->setValue(this->value + this->smallChange); + if (this->mouseDownIndex == 3) { + this->setValue(this->value + this->smallChange, true); } } else { - if (this->mouseDownIndex == 0) { - this->setValue(this->value + this->smallChange); + if (this->mouseDownIndex == 4) { + this->setValue(this->value + this->smallChange, true); } } diff --git a/widgets/scrollbar.h b/widgets/scrollbar.h index 3e23df8c..b647c786 100644 --- a/widgets/scrollbar.h +++ b/widgets/scrollbar.h @@ -67,6 +67,7 @@ public: if (animated) { this->valueAnimation.stop(); this->valueAnimation.setStartValue(this->value); + this->valueAnimation.setEndValue(value); this->valueAnimation.start(); } else {