Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qtabbar_p.h

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5959#include <qicon.h>
    6060#include <qtoolbutton.h>
    61 #include <qtimeline.h>
    62 #include <qhash.h>
    6361#include <qdebug.h>
     62
    6463
    6564#ifndef QT_NO_TABBAR
     
    7069
    7170QT_BEGIN_NAMESPACE
    72 
    7371
    7472class QTabBarPrivate  : public QWidgetPrivate
     
    7775public:
    7876    QTabBarPrivate()
    79         :currentIndex(-1), pressedIndex(-1),
    80          shape(QTabBar::RoundedNorth),
    81          layoutDirty(false), drawBase(true), scrollOffset(0), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false) {}
     77        :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false),
     78        drawBase(true), scrollOffset(0), useScrollButtonsSetByUser(false) , expanding(true), closeButtonOnTabs(false),
     79        selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false),
     80        dragInProgress(false), documentMode(false), movingTab(0)
     81#ifdef Q_WS_MAC
     82        , previousPressedIndex(-1)
     83#endif
     84        {}
    8285
    8386    int currentIndex;
     
    9093    struct Tab {
    9194        inline Tab(const QIcon &ico, const QString &txt)
    92             : enabled(true)
    93             , shortcutId(0)
    94             , text(txt)
    95             , icon(ico)
    96             , leftWidget(0)
    97             , rightWidget(0)
    98             , lastTab(-1)
    99             , timeLine(0)
    100             , dragOffset(0)
    101             , hidLeft(false)
    102             , hidRight(false)
     95            : enabled(true) , shortcutId(0), text(txt), icon(ico),
     96            leftWidget(0), rightWidget(0), lastTab(-1), dragOffset(0)
     97#ifndef QT_NO_ANIMATION
     98            , animation(0)
     99#endif //QT_NO_ANIMATION
    103100        {}
     101
    104102        bool enabled;
    105103        int shortcutId;
     
    121119        QWidget *rightWidget;
    122120        int lastTab;
    123 
    124         QTimeLine *timeLine;
    125121        int dragOffset;
    126         QPixmap animatingCache;
    127         bool hidLeft;
    128         bool hidRight;
    129 
    130         void makeTimeLine(QWidget *q) {
    131             if (timeLine)
    132                 return;
    133             timeLine = new QTimeLine(ANIMATION_DURATION, q);
    134             q->connect(timeLine, SIGNAL(frameChanged(int)), q, SLOT(_q_moveTab(int)));
    135             q->connect(timeLine, SIGNAL(finished()), q, SLOT(_q_moveTabFinished()));
     122
     123#ifndef QT_NO_ANIMATION
     124        ~Tab() { delete animation; }
     125        struct TabBarAnimation : public QVariantAnimation {
     126            TabBarAnimation(Tab *t, QTabBarPrivate *_priv) : tab(t), priv(_priv)
     127            { setEasingCurve(QEasingCurve::InOutQuad); }
     128
     129            void updateCurrentValue(const QVariant &current)
     130            { priv->moveTab(priv->tabList.indexOf(*tab), current.toInt()); }
     131
     132            void updateState(State, State newState)
     133            { if (newState == Stopped) priv->moveTabFinished(priv->tabList.indexOf(*tab)); }
     134        private:
     135            //these are needed for the callbacks
     136            Tab *tab;
     137            QTabBarPrivate *priv;
     138        } *animation;
     139
     140        void startAnimation(QTabBarPrivate *priv, int duration) {
     141            if (!animation)
     142                animation = new TabBarAnimation(this, priv);
     143            animation->setStartValue(dragOffset);
     144            animation->setEndValue(0);
     145            animation->setDuration(duration);
     146            animation->start();
    136147        }
    137 
    138         void hideWidgets() {
    139             if (!hidRight && rightWidget) {
    140                 hidRight = rightWidget->isVisible();
    141                 rightWidget->hide();
    142             }
    143 
    144             if (!hidLeft && leftWidget) {
    145                 hidLeft = leftWidget->isVisible();
    146                 leftWidget->hide();
    147             }
    148         }
    149 
    150         void unHideWidgets() {
    151             if (leftWidget && hidLeft)
    152                 leftWidget->show();
    153             hidLeft = false;
    154             if (rightWidget && hidRight)
    155                 rightWidget->show();
    156             hidRight = false;
    157         }
    158 
     148#else
     149        void startAnimation(QTabBarPrivate *priv, int duration)
     150        { Q_UNUSED(duration); priv->moveTabFinished(priv->tabList.indexOf(*this)); }
     151#endif //QT_NO_ANIMATION
    159152    };
    160153    QList<Tab> tabList;
    161     QHash<QTimeLine*, int> animations;
    162154
    163155    int calculateNewPosition(int from, int to, int index) const;
     
    172164
    173165    inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); }
     166
    174167
    175168    QSize minimumTabSizeHint(int index);
     
    180173    void _q_scrollTabs();
    181174    void _q_closeTab();
    182     void _q_moveTab(int);
    183     void _q_moveTabFinished();
    184     void _q_moveTabFinished(int offset);
     175    void moveTab(int index, int offset);
     176    void moveTabFinished(int index);
    185177    QRect hoverRect;
    186178
    187     void grabCache(int start, int end, bool unhide);
    188179    void refresh();
    189180    void layoutTabs();
     
    191182    void layoutTab(int index);
    192183    void updateMacBorderMetrics();
     184
    193185
    194186    void makeVisible(int index);
     
    196188    Qt::TextElideMode elideMode;
    197189    bool useScrollButtons;
     190
    198191
    199192    bool expanding;
     
    207200    bool documentMode;
    208201
     202
     203
     204
     205
    209206    // shared by tabwidget and qtabbar
    210207    static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size)
Note: See TracChangeset for help on using the changeset viewer.