added some dank tab animations

This commit is contained in:
fourtf 2017-01-26 05:26:21 +01:00
parent 700c756f5a
commit 4b2ddb0bbb
7 changed files with 53 additions and 35 deletions

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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("<no title>")
, 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;

View file

@ -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;

View file

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

View file

@ -67,6 +67,7 @@ public:
if (animated) {
this->valueAnimation.stop();
this->valueAnimation.setStartValue(this->value);
this->valueAnimation.setEndValue(value);
this->valueAnimation.start();
} else {