2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_TABBAR_H
|
|
|
|
#define PLASMA_TABBAR_H
|
|
|
|
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
2008-11-06 00:28:07 +01:00
|
|
|
|
|
|
|
#include <ktabbar.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
class QString;
|
|
|
|
class QIcon;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class TabBarPrivate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class TabBar plasma/widgets/tabbar.h <Plasma/Widgets/TabBar>
|
|
|
|
*
|
|
|
|
* @short A tab bar widget, to be used for tabbed interfaces.
|
|
|
|
*
|
|
|
|
* Provides a Tab bar for use in a tabbed interface where each page is a QGraphicsLayoutItem.
|
|
|
|
* Only one of them is displayed at a given time. It is possible to add and remove tabs
|
|
|
|
* or modify their text label or their icon.
|
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT TabBar : public QGraphicsWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2008-11-06 00:28:07 +01:00
|
|
|
Q_PROPERTY(KTabBar *nativeWidget READ nativeWidget)
|
2008-11-04 00:08:39 +01:00
|
|
|
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex)
|
|
|
|
Q_PROPERTY(int count READ count)
|
|
|
|
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
|
2009-02-04 11:32:20 +01:00
|
|
|
Q_PROPERTY(bool tabBarShown READ isTabBarShown WRITE setTabBarShown)
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructs a new TabBar
|
|
|
|
*
|
|
|
|
* @arg parent the parent of this widget
|
|
|
|
*/
|
|
|
|
explicit TabBar(QGraphicsWidget *parent = 0);
|
|
|
|
~TabBar();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the desired position
|
|
|
|
*
|
|
|
|
* @arg index the position where to insert the new tab,
|
|
|
|
* if index <=0 will be the first position,
|
|
|
|
* if index >= count() will be the last
|
|
|
|
* @arg icon the icon for this tab
|
|
|
|
* @arg label the text label of the tab
|
|
|
|
* @arg content the page content that will be shown by this tab
|
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
|
|
|
int insertTab(int index, const QIcon &icon, const QString &label,
|
|
|
|
QGraphicsLayoutItem *content = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the desired position
|
|
|
|
* This is an overloaded member provided for convenience
|
|
|
|
* equivalent to insertTab(index, QIcon(), label);
|
|
|
|
*
|
|
|
|
* @arg index the position where to insert the new tab,
|
|
|
|
* if index <=0 will be the first position,
|
|
|
|
* if index >= count() will be the last
|
|
|
|
* @arg label the text label of the tab
|
|
|
|
* @arg content the page content that will be shown by this tab
|
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
|
|
|
int insertTab(int index, const QString &label, QGraphicsLayoutItem *content = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the last position
|
|
|
|
*
|
|
|
|
* @arg icon the icon for this tab
|
|
|
|
* @arg label the text label of the tab
|
|
|
|
* @arg content the page content that will be shown by this tab
|
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
|
|
|
int addTab(const QIcon &icon, const QString &label, QGraphicsLayoutItem *content = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the last position
|
|
|
|
* This is an overloaded member provided for convenience
|
|
|
|
* equivalent to addTab(QIcon(), label, page)
|
|
|
|
*
|
|
|
|
* @arg label the text label of the tab
|
|
|
|
* @arg content the page content that will be shown by this tab
|
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
|
|
|
int addTab(const QString &label, QGraphicsLayoutItem *content = 0);
|
|
|
|
|
|
|
|
/**
|
2009-07-29 22:30:07 +02:00
|
|
|
* Removes a tab, contents are deleted
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* @arg index the index of the tab to remove
|
|
|
|
*/
|
|
|
|
void removeTab(int index);
|
|
|
|
|
2009-07-29 22:30:07 +02:00
|
|
|
/**
|
|
|
|
* Removes a tab, the page is reparented to 0 and is returned
|
|
|
|
*
|
|
|
|
* @arg index the index of the tab to remove
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
|
|
|
QGraphicsLayoutItem *takeTab(int index);
|
2009-09-02 17:54:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the contents of a page
|
|
|
|
*
|
|
|
|
* @arg index the index of the tab to retrieve
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
|
|
|
QGraphicsLayoutItem *tabAt(int index);
|
2009-07-29 22:30:07 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* @return the index of the tab currently active
|
|
|
|
*/
|
|
|
|
int currentIndex() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the number of tabs in this tabbar
|
|
|
|
*/
|
|
|
|
int count() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the text label of the given tab
|
|
|
|
*
|
|
|
|
* @arg index the index of the tab to modify
|
|
|
|
* @arg label the new text label of the given tab
|
|
|
|
*/
|
|
|
|
void setTabText(int index, const QString &label);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the text label of the given tab
|
|
|
|
*
|
|
|
|
* @arg index the index of the tab we want to know its label
|
|
|
|
*/
|
|
|
|
QString tabText(int index) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an icon for a given tab
|
|
|
|
*
|
|
|
|
* @arg index the index of the tab to modify
|
|
|
|
* @arg icon the new icon for the given tab
|
|
|
|
*/
|
|
|
|
void setTabIcon(int index, const QIcon &icon);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the current icon for a given tab
|
|
|
|
*
|
|
|
|
* @arg index the index of the tab we want to know its icon
|
|
|
|
*/
|
|
|
|
QIcon tabIcon(int index) const;
|
|
|
|
|
2009-02-04 11:32:20 +01:00
|
|
|
/**
|
|
|
|
* shows or hides the tabbar, used if you just want to display the
|
|
|
|
* pages, when the tabbar doesn't have content pages at all this
|
|
|
|
* function has no effect
|
|
|
|
*
|
|
|
|
* @arg show true if we want to show the tabbar
|
2009-02-04 11:59:15 +01:00
|
|
|
* @since 4.3
|
2009-02-04 11:32:20 +01:00
|
|
|
*/
|
|
|
|
void setTabBarShown(bool show);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the tabbar is shown
|
2009-02-04 11:59:15 +01:00
|
|
|
* @since 4.3
|
2009-02-04 11:32:20 +01:00
|
|
|
*/
|
|
|
|
bool isTabBarShown() const;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* Sets the stylesheet used to control the visual display of this TabBar
|
|
|
|
*
|
|
|
|
* @arg stylesheet a CSS string
|
|
|
|
*/
|
|
|
|
void setStyleSheet(const QString &stylesheet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the stylesheet currently used with this widget
|
|
|
|
*/
|
|
|
|
QString styleSheet() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the native widget wrapped by this TabBar
|
|
|
|
*/
|
2008-11-06 00:28:07 +01:00
|
|
|
KTabBar *nativeWidget() const;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Activate a given tab
|
|
|
|
*
|
|
|
|
* @arg index the index of the tab to activate
|
|
|
|
*/
|
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Emitted when the active tab changes
|
|
|
|
*
|
|
|
|
* @arg index the newly activated tab
|
|
|
|
*/
|
|
|
|
void currentChanged(int index);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
2008-11-18 16:27:04 +01:00
|
|
|
void resizeEvent(QGraphicsSceneResizeEvent * event);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
TabBarPrivate * const d;
|
|
|
|
|
|
|
|
Q_PRIVATE_SLOT(d, void slidingCompleted(QGraphicsItem *item))
|
|
|
|
Q_PRIVATE_SLOT(d, void shapeChanged(const QTabBar::Shape shape))
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|