Public Types | Signals | Public Member Functions | Protected Member Functions | Properties | Friends

QxtTabWidget Class Reference
[QxtGui]

An extended QTabWidget. More...

#include <qxttabwidget.h>

Collaboration diagram for QxtTabWidget:
Collaboration graph
[legend]

List of all members.

Public Types

enum  TabMovementMode { NoMovement, InPlaceMovement, DragDropMovement }

Signals

void tabContextMenuRequested (int index, const QPoint &globalPos)

Public Member Functions

 QxtTabWidget (QWidget *parent=0)
virtual ~QxtTabWidget ()
bool alwaysShowTabBar () const
void setAlwaysShowTabBar (bool always)
Qt::ContextMenuPolicy tabContextMenuPolicy () const
void setTabContextMenuPolicy (Qt::ContextMenuPolicy policy)
TabMovementMode tabMovementMode () const
void setTabMovementMode (TabMovementMode mode)
void addTabAction (int index, QAction *action)
QAction * addTabAction (int index, const QString &text)
QAction * addTabAction (int index, const QIcon &icon, const QString &text)
QAction * addTabAction (int index, const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut=0)
QAction * addTabAction (int index, const QIcon &icon, const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut=0)
void addTabActions (int index, QList< QAction * > actions)
void clearTabActions (int index)
void insertTabAction (int index, QAction *before, QAction *action)
void insertTabActions (int index, QAction *before, QList< QAction * > actions)
void removeTabAction (int index, QAction *action)
QList< QAction * > tabActions (int index) const
QMovie * tabAnimation (int index) const
void setTabAnimation (int index, QMovie *animation, bool start=true)
void setTabAnimation (int index, const QString &fileName, bool start=true)
QMovie * takeTabAnimation (int index)

Protected Member Functions

QxtTabBartabBar () const
virtual void tabInserted (int index)
virtual void tabRemoved (int index)
virtual void contextMenuEvent (QContextMenuEvent *event)
virtual void tabContextMenuEvent (int index, QContextMenuEvent *event)

Properties

bool alwaysShowTabBar
 This property holds whether the tab bar is shown always regardless of how many tabs there are.
Qt::ContextMenuPolicy tabContextMenuPolicy
 This property holds how the tab specific context menus are handled.
TabMovementMode tabMovementMode

Friends

class QxtTabWidgetPrivate

Detailed Description

An extended QTabWidget.

QxtTabWidget provides some convenience for handling tab specific context menus and animations.

Example usage:

    QxtTabWidget* tabWidget = new QxtTabWidget();
    tabWidget->addTab(tab0, "1");
    tabWidget->addTab(tab1, "2");

    QList<QAction*> actions0;
    actions0 << new QAction("Quisque", tab0) << new QAction("Aenean", tab0);
    QList<QAction*> actions1;
    actions1 << new QAction("Phasellus", tab1) << new QAction("Maecenas", tab1);

    tabWidget->setTabContextMenuPolicy(Qt::ActionsContextMenu);
    tabWidget->addTabActions(0, actions0);
    tabWidget->addTabActions(1, actions1);
qxttabwidget.png

QxtTabWidget in WindowsXP style.

Note:
http://www.trolltech.com/developer/task-tracker/index_html?method=entry&amp;id=137891

Definition at line 36 of file qxttabwidget.h.


Member Enumeration Documentation

Enumerator:
NoMovement 
InPlaceMovement 
DragDropMovement 

Definition at line 54 of file qxttabwidget.h.


Constructor & Destructor Documentation

QxtTabWidget::QxtTabWidget ( QWidget *  parent = 0 ) [explicit]

Constructs a new QxtTabWidget with parent.

Definition at line 100 of file qxttabwidget.cpp.

References QXT_INIT_PRIVATE.

                                          : QTabWidget(parent)
{
    QXT_INIT_PRIVATE(QxtTabWidget);
    QTabWidget::setTabBar(new QxtTabBar);
}
QxtTabWidget::~QxtTabWidget (  ) [virtual]

Destructs the tab widget.

Definition at line 109 of file qxttabwidget.cpp.

{
}

Member Function Documentation

void QxtTabWidget::addTabAction ( int  index,
QAction *  action 
)

Appends the action to the list of actions of the tab at index.

See also:
removeTabAction(), insertTabAction(), tabActions()

Definition at line 181 of file qxttabwidget.cpp.

References insertTabAction().

Referenced by addTabAction().

{
    insertTabAction(index, 0, action);
}
QAction * QxtTabWidget::addTabAction ( int  index,
const QString &  text 
)

This convenience function creates a new action with text. The function adds the newly created action to the list of actions of the tab at index, and returns it.

See also:
addTabAction()

Definition at line 193 of file qxttabwidget.cpp.

References addTabAction().

{
    return addTabAction(index, QIcon(), text, 0, 0);
}
QAction * QxtTabWidget::addTabAction ( int  index,
const QIcon &  icon,
const QString &  text 
)

This convenience function creates a new action with icon and text. The function adds the newly created action to the list of actions of the tab at index, and returns it.

See also:
addTabAction()

Definition at line 205 of file qxttabwidget.cpp.

References addTabAction().

{
    return addTabAction(index, icon, text, 0, 0);
}
QAction * QxtTabWidget::addTabAction ( int  index,
const QString &  text,
const QObject *  receiver,
const char *  member,
const QKeySequence &  shortcut = 0 
)

This convenience function creates a new action with text and an optional shortcut. The action's triggered() signal is connected to the receiver's member slot. The function adds the newly created action to the list of actions of the tab at index, and returns it.

Note:
In order to make it possible for the shortcut to work even when the context menu is not open, the action must be added to a visible widget. The corresponding tab is a good alternative.
    QWidget* tab = createNewTab();
    tabWidget->addTab(tab, title);
    QAction* action = tabWidget->addTabAction(index, tr("Close"), this, SLOT(closeCurrentTab()), tr("Ctrl+W"));
    tab->addAction(act);
See also:
addTabAction(), QWidget::addAction()

Definition at line 230 of file qxttabwidget.cpp.

References addTabAction().

{
    return addTabAction(index, QIcon(), text, receiver, member, shortcut);
}
QAction * QxtTabWidget::addTabAction ( int  index,
const QIcon &  icon,
const QString &  text,
const QObject *  receiver,
const char *  member,
const QKeySequence &  shortcut = 0 
)

This convenience function creates a new action with icon, text and an optional shortcut. The action's triggered() signal is connected to the receiver's member slot. The function adds the newly created action to the list of actions of the tab at index, and returns it.

See also:
addTabAction()

Definition at line 243 of file qxttabwidget.cpp.

References addTabAction().

{
    QAction* action = new QAction(icon, text, this);
    addTabAction(index, action);
    if (receiver && member)
        connect(action, SIGNAL(triggered()), receiver, member);
    action->setShortcut(shortcut);
    return action;
}
void QxtTabWidget::addTabActions ( int  index,
QList< QAction * >  actions 
)

Appends the actions to the list of actions of the tab at index.

See also:
removeTabAction(), addTabAction()

Definition at line 259 of file qxttabwidget.cpp.

References insertTabAction().

{
    foreach(QAction* action, actions)
    {
        insertTabAction(index, 0, action);
    }
}
bool QxtTabWidget::alwaysShowTabBar (  ) const
void QxtTabWidget::clearTabActions ( int  index )

Clears the list of actions of the tab at index.

Note:
Only actions owned by the tab widget are deleted.
See also:
removeTabAction(), addTabAction()

Definition at line 274 of file qxttabwidget.cpp.

References removeTabAction().

{
    Q_ASSERT(index >= 0 && index < qxt_d().actions.count());

    while (qxt_d().actions[index].count())
    {
        QAction* action = qxt_d().actions[index].last();
        removeTabAction(index, action);
        if (action->parent() == this)
            delete action;
    }
}
void QxtTabWidget::contextMenuEvent ( QContextMenuEvent *  event ) [protected, virtual]

Definition at line 462 of file qxttabwidget.cpp.

References tabBar(), tabContextMenuEvent(), and tabContextMenuRequested().

{
    const QPoint& pos = event->pos();
    if (!tabBar()->geometry().contains(pos))
        return QTabWidget::contextMenuEvent(event);

    const int index = qxt_d().tabIndexAt(event->pos());
    switch (qxt_d().policy)
    {
    case Qt::NoContextMenu:
        event->ignore();
        break;

#if QT_VERSION >= 0x040200
    case Qt::PreventContextMenu:
        event->accept();
        break;
#endif // QT_VERSION

    case Qt::ActionsContextMenu:
        if (index != -1 && qxt_d().actions.at(index).count())
        {
            QMenu::exec(qxt_d().actions.at(index), event->globalPos());
        }
        break;

    case Qt::CustomContextMenu:
        if (index != -1)
        {
            emit tabContextMenuRequested(index, event->globalPos());
        }
        break;

    case Qt::DefaultContextMenu:
    default:
        if (index != -1)
        {
            tabContextMenuEvent(index, event);
        }
        break;
    }
}
void QxtTabWidget::insertTabAction ( int  index,
QAction *  before,
QAction *  action 
)

Inserts the action to the list of actions of the tab at index, before the action before. It appends the action if before is 0.

See also:
removeTabAction(), addTabAction(), tabContextMenuPolicy, tabActions()

Definition at line 294 of file qxttabwidget.cpp.

References removeTabAction().

Referenced by addTabAction(), addTabActions(), and insertTabActions().

{
    Q_ASSERT(index >= 0 && index < qxt_d().actions.count());

    if (!action)
    {
        qWarning("QxtTabWidget::insertTabAction: Attempt to insert a null action");
        return;
    }

    const Actions& actions = qxt_d().actions.at(index);
    if (actions.contains(action))
        removeTabAction(index, action);

    int pos = actions.indexOf(before);
    if (pos < 0)
    {
        before = 0;
        pos = actions.count();
    }
    qxt_d().actions[index].insert(pos, action);

    QActionEvent e(QEvent::ActionAdded, action, before);
    QApplication::sendEvent(this, &e);
}
void QxtTabWidget::insertTabActions ( int  index,
QAction *  before,
QList< QAction * >  actions 
)

Inserts the actions to the list of actions of the tab at index, before the action before. It appends the action if before is 0.

See also:
removeAction(), QMenu, insertAction(), contextMenuPolicy

Definition at line 327 of file qxttabwidget.cpp.

References insertTabAction().

{
    foreach(QAction* action, actions)
    {
        insertTabAction(index, before, action);
    }
}
void QxtTabWidget::removeTabAction ( int  index,
QAction *  action 
)

Removes the action action from the list of actions of the tab at index.

Note:
The removed action is not deleted.
See also:
insertTabAction(), tabActions(), insertTabAction()

Definition at line 343 of file qxttabwidget.cpp.

Referenced by clearTabActions(), and insertTabAction().

{
    Q_ASSERT(index >= 0 && index < qxt_d().actions.count());

    if (!action)
    {
        qWarning("QxtTabWidget::removeTabAction: Attempt to remove a null action");
        return;
    }

    if (qxt_d().actions[index].removeAll(action))
    {
        QActionEvent e(QEvent::ActionRemoved, action);
        QApplication::sendEvent(this, &e);
    }
}
void QxtTabWidget::setAlwaysShowTabBar ( bool  always )

Definition at line 128 of file qxttabwidget.cpp.

References tabBar().

{
    qxt_d().always = always;
    tabBar()->setVisible(always || count() > 1);
}
void QxtTabWidget::setTabAnimation ( int  index,
QMovie *  animation,
bool  start = true 
)

Sets the animation of the tab at index and optionally start the animation.

See also:
tabAnimation()

Definition at line 390 of file qxttabwidget.cpp.

References takeTabAnimation().

Referenced by setTabAnimation().

{
    Q_ASSERT(index >= 0 && index < qxt_d().animations.count());
    delete takeTabAnimation(index);
    qxt_d().animations[index] = animation;
    if (animation)
    {
        connect(animation, SIGNAL(frameChanged(int)), &qxt_d(), SLOT(setMovieFrame(int)));
        if (start)
            animation->start();
    }
}
void QxtTabWidget::setTabAnimation ( int  index,
const QString &  fileName,
bool  start = true 
)

This is an overloaded member function, provided for convenience.

The QMovie animation is constructed as this as parent.

See also:
setTabAnimation()

Definition at line 410 of file qxttabwidget.cpp.

References setTabAnimation().

{
    setTabAnimation(index, new QMovie(fileName, QByteArray(), this), start);
}
void QxtTabWidget::setTabContextMenuPolicy ( Qt::ContextMenuPolicy  policy )

Definition at line 170 of file qxttabwidget.cpp.

{
    qxt_d().policy = policy;
}
void QxtTabWidget::setTabMovementMode ( TabMovementMode  mode )
QList< QAction * > QxtTabWidget::tabActions ( int  index ) const

Returns the (possibly empty) list of actions for the tab at index.

See also:
tabContextMenuPolicy, insertTabAction(), removeTabAction()

Definition at line 366 of file qxttabwidget.cpp.

{
    Q_ASSERT(index >= 0 && index < qxt_d().actions.count());
    return qxt_d().actions.at(index);
}
QMovie * QxtTabWidget::tabAnimation ( int  index ) const

Returns the animation of the tab at index or 0 if no animation has been set.

See also:
setTabAnimation()

Definition at line 378 of file qxttabwidget.cpp.

{
    Q_ASSERT(index >= 0 && index < qxt_d().animations.count());
    return qxt_d().animations.at(index);
}
QxtTabBar * QxtTabWidget::tabBar (  ) const [protected]
void QxtTabWidget::tabContextMenuEvent ( int  index,
QContextMenuEvent *  event 
) [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive context menu events for the tab at index.

The handler is called when tabContextMenuPolicy is Qt::DefaultContextMenu.

The default implementation ignores the context menu event.

See also:
tabContextMenuPolicy, tabContextMenuRequested()

Definition at line 516 of file qxttabwidget.cpp.

Referenced by contextMenuEvent().

{
    Q_UNUSED(index);
    event->ignore();
}
Qt::ContextMenuPolicy QxtTabWidget::tabContextMenuPolicy (  ) const
QxtTabWidget::tabContextMenuRequested ( int  index,
const QPoint &  globalPos 
) [signal]

This signal is emitted whenever the context menu is requested over tab at index at globalPos.

Referenced by contextMenuEvent().

void QxtTabWidget::tabInserted ( int  index ) [protected, virtual]

Definition at line 436 of file qxttabwidget.cpp.

References tabBar().

{
    Q_ASSERT(index >= 0);
    Q_ASSERT(index <= qxt_d().actions.count());
    Q_ASSERT(index <= qxt_d().animations.count());
    qxt_d().actions.insert(index, Actions());
    qxt_d().animations.insert(index, 0);
    tabBar()->setVisible(qxt_d().always || count() > 1);
}
TabMovementMode QxtTabWidget::tabMovementMode (  ) const
void QxtTabWidget::tabRemoved ( int  index ) [protected, virtual]

Definition at line 449 of file qxttabwidget.cpp.

References tabBar().

{
    Q_ASSERT(index >= 0);
    Q_ASSERT(index < qxt_d().actions.count());
    Q_ASSERT(index < qxt_d().animations.count());
    qxt_d().actions.removeAt(index);
    qxt_d().animations.removeAt(index);
    tabBar()->setVisible(qxt_d().always || count() > 1);
}
QMovie * QxtTabWidget::takeTabAnimation ( int  index )

Removes the animation of the tab at index and returns it.

See also:
tabAnimation()

Definition at line 420 of file qxttabwidget.cpp.

Referenced by setTabAnimation().

{
    Q_ASSERT(index >= 0 && index < qxt_d().animations.count());
    QMovie* animation = qxt_d().animations.at(index);
    qxt_d().animations[index] = 0;
    return animation;
}

Friends And Related Function Documentation

friend class QxtTabWidgetPrivate [friend]

Definition at line 39 of file qxttabwidget.h.


Property Documentation

bool QxtTabWidget::alwaysShowTabBar [read, write]

This property holds whether the tab bar is shown always regardless of how many tabs there are.

The default value of this property is true.

Set this property to false if you want to show the tab bar only in case there are more than one tabs.

Definition at line 39 of file qxttabwidget.h.

Qt::ContextMenuPolicy QxtTabWidget::tabContextMenuPolicy [read, write]

This property holds how the tab specific context menus are handled.

The default value of this property is Qt::DefaultContextMenu, which means that the tabContextMenuEvent() handler is called. Other values are Qt::NoContextMenu, Qt::PreventContextMenu (since Qt 4.2), Qt::ActionsContextMenu, and Qt::CustomContextMenu. With Qt::CustomContextMenu, the signal tabContextMenuRequested() is emitted.

See also:
tabContextMenuEvent(), tabContextMenuRequested(), tabActions()

Definition at line 41 of file qxttabwidget.h.

QxtTabWidget::TabMovementMode QxtTabWidget::tabMovementMode [read, write]

Definition at line 42 of file qxttabwidget.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines