Fixed an animation glitch with the sidebar

We need to kill the fadeins before fading out.
Otherwise we might get into weird states.
This commit is contained in:
Jens Bache-Wiig
2010-02-18 13:57:33 +01:00
parent 0dccaf45a2
commit 41885a192d
3 changed files with 23 additions and 27 deletions

View File

@@ -55,20 +55,18 @@ const int FancyTabBar::m_textPadding = 4;
void FancyTab::fadeIn() void FancyTab::fadeIn()
{ {
QPropertyAnimation *animation; animator.stop();
animation = new QPropertyAnimation(this, "fader"); animator.setDuration(80);
animation->setDuration(70); animator.setEndValue(40);
animation->setEndValue(50); animator.start();
animation->start(QAbstractAnimation::DeleteWhenStopped);
} }
void FancyTab::fadeOut() void FancyTab::fadeOut()
{ {
QPropertyAnimation *animation; animator.stop();
animation = new QPropertyAnimation(this, "fader"); animator.setDuration(160);
animation->setDuration(200); animator.setEndValue(0);
animation->setEndValue(0); animator.start();
animation->start(QAbstractAnimation::DeleteWhenStopped);
} }
FancyTabBar::FancyTabBar(QWidget *parent) FancyTabBar::FancyTabBar(QWidget *parent)
@@ -176,14 +174,11 @@ void FancyTabBar::enterEvent(QEvent *e)
void FancyTabBar::leaveEvent(QEvent *e) void FancyTabBar::leaveEvent(QEvent *e)
{ {
Q_UNUSED(e) Q_UNUSED(e)
if (validIndex(m_hoverIndex)) { m_hoverIndex = -1;
m_hoverIndex = -1; update(m_hoverRect);
update(m_hoverRect); m_hoverRect = QRect();
m_hoverRect = QRect(); for (int i = 0 ; i < m_tabs.count() ; ++i) {
for (int i = 0 ; i < m_tabs.count() ; ++i) { m_tabs[i]->fadeOut();
if (m_tabs[i]->fader() > 0)
m_tabs[i]->fadeOut();
}
} }
} }
@@ -245,9 +240,6 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
hover = false; // Do not hover on Mac hover = false; // Do not hover on Mac
#endif #endif
QColor hoverColor;
hoverColor = QColor(255, 255, 255, m_tabs[tabIndex]->fader());
if (selected) { if (selected) {
//background //background
painter->fillRect(rect, QColor(220, 220, 220)); painter->fillRect(rect, QColor(220, 220, 220));
@@ -293,7 +285,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
} else { } else {
painter->setPen(selected ? Utils::StyleHelper::panelTextColor() : QColor(255, 255, 255, 120)); painter->setPen(selected ? Utils::StyleHelper::panelTextColor() : QColor(255, 255, 255, 120));
} }
#ifndef Q_WS_MAC
if (!selected && enabled) { if (!selected && enabled) {
painter->save(); painter->save();
int fader = int(m_tabs[tabIndex]->fader()); int fader = int(m_tabs[tabIndex]->fader());
@@ -307,7 +299,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->drawLine(rect.bottomLeft(), rect.bottomRight());
painter->restore(); painter->restore();
} }
#endif
int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
tabIconRect.adjust(0, 4, 0, -textHeight); tabIconRect.adjust(0, 4, 0, -textHeight);
int iconSize = qMin(tabIconRect.width(), tabIconRect.height()); int iconSize = qMin(tabIconRect.width(), tabIconRect.height());

View File

@@ -35,7 +35,7 @@
#include <QtGui/QStyleOptionTabV2> #include <QtGui/QStyleOptionTabV2>
#include <QtCore/QTimeLine> #include <QtCore/QTimeLine>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QPropertyAnimation>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QPainter; class QPainter;
class QStackedLayout; class QStackedLayout;
@@ -50,7 +50,10 @@ class FancyTab : public QObject{
Q_PROPERTY(float fader READ fader WRITE setFader) Q_PROPERTY(float fader READ fader WRITE setFader)
public: public:
FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0) {} FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0) {
animator.setPropertyName("fader");
animator.setTargetObject(this);
}
float fader() { return m_fader; } float fader() { return m_fader; }
void setFader(float value) { m_fader = value; tabbar->update(); } void setFader(float value) { m_fader = value; tabbar->update(); }
@@ -61,7 +64,9 @@ public:
QString text; QString text;
QString toolTip; QString toolTip;
bool enabled; bool enabled;
private: private:
QPropertyAnimation animator;
QWidget *tabbar; QWidget *tabbar;
float m_fader; float m_fader;
}; };

View File

@@ -698,8 +698,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
d->m_projectSelectorAction->setEnabled(false); d->m_projectSelectorAction->setEnabled(false);
QWidget *mainWindow = Core::ICore::instance()->mainWindow(); QWidget *mainWindow = Core::ICore::instance()->mainWindow();
d->m_targetSelector = new Internal::MiniProjectTargetSelector(d->m_projectSelectorAction, mainWindow); d->m_targetSelector = new Internal::MiniProjectTargetSelector(d->m_projectSelectorAction, mainWindow);
d->m_projectSelectorAction->setCheckable(true); connect(d->m_projectSelectorAction, SIGNAL(triggered()), d->m_targetSelector, SLOT(show()));
connect(d->m_projectSelectorAction, SIGNAL(toggled(bool)), d->m_targetSelector, SLOT(setVisible(bool)));
modeManager->addProjectSelector(d->m_projectSelectorAction); modeManager->addProjectSelector(d->m_projectSelectorAction);
cmd = am->registerAction(d->m_projectSelectorAction, ProjectExplorer::Constants::SELECTTARGET, cmd = am->registerAction(d->m_projectSelectorAction, ProjectExplorer::Constants::SELECTTARGET,