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)
|
2010-10-24 23:36:50 +02:00
|
|
|
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
|
2008-11-04 00:08:39 +01:00
|
|
|
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)
|
2010-07-12 10:29:49 +02:00
|
|
|
Q_PROPERTY(QGraphicsWidget *firstPositionWidget READ firstPositionWidget WRITE setFirstPositionWidget)
|
|
|
|
Q_PROPERTY(QGraphicsWidget *lastPositionWidget READ lastPositionWidget WRITE setLastPositionWidget)
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructs a new TabBar
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param parent the parent of this widget
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
explicit TabBar(QGraphicsWidget *parent = 0);
|
|
|
|
~TabBar();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the desired position
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the position where to insert the new tab,
|
2008-11-04 00:08:39 +01:00
|
|
|
* if index <=0 will be the first position,
|
|
|
|
* if index >= count() will be the last
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param icon the icon for this tab
|
|
|
|
* @param label the text label of the tab
|
|
|
|
* @param content the page content that will be shown by this tab
|
2008-11-04 00:08:39 +01:00
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE int insertTab(int index, const QIcon &icon, const QString &label,
|
|
|
|
QGraphicsLayoutItem *content = 0);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the desired position
|
|
|
|
* This is an overloaded member provided for convenience
|
|
|
|
* equivalent to insertTab(index, QIcon(), label);
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the position where to insert the new tab,
|
2008-11-04 00:08:39 +01:00
|
|
|
* if index <=0 will be the first position,
|
|
|
|
* if index >= count() will be the last
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param label the text label of the tab
|
|
|
|
* @param content the page content that will be shown by this tab
|
2008-11-04 00:08:39 +01:00
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE int insertTab(int index, const QString &label, QGraphicsLayoutItem *content = 0);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the last position
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param icon the icon for this tab
|
|
|
|
* @param label the text label of the tab
|
|
|
|
* @param content the page content that will be shown by this tab
|
2008-11-04 00:08:39 +01:00
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE int addTab(const QIcon &icon, const QString &label, QGraphicsLayoutItem *content = 0);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new tab in the last position
|
|
|
|
* This is an overloaded member provided for convenience
|
|
|
|
* equivalent to addTab(QIcon(), label, page)
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param label the text label of the tab
|
|
|
|
* @param content the page content that will be shown by this tab
|
2008-11-04 00:08:39 +01:00
|
|
|
* @return the index of the inserted tab
|
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE int addTab(const QString &label, QGraphicsLayoutItem *content = 0);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
2009-07-29 22:30:07 +02:00
|
|
|
* Removes a tab, contents are deleted
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab to remove
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE void removeTab(int index);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-07-29 22:30:07 +02:00
|
|
|
/**
|
|
|
|
* Removes a tab, the page is reparented to 0 and is returned
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab to remove
|
2009-07-29 22:30:07 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE QGraphicsLayoutItem *takeTab(int index);
|
2009-09-13 21:18:29 +02:00
|
|
|
|
2009-09-02 17:54:18 +02:00
|
|
|
/**
|
|
|
|
* Returns the contents of a page
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab to retrieve
|
2009-09-02 17:54:18 +02:00
|
|
|
* @since 4.4
|
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE 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
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab to modify
|
|
|
|
* @param label the new text label of the given tab
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE void setTabText(int index, const QString &label);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the text label of the given tab
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab we want to know its label
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE QString tabText(int index) const;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an icon for a given tab
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab to modify
|
|
|
|
* @param icon the new icon for the given tab
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE void setTabIcon(int index, const QIcon &icon);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the current icon for a given tab
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab we want to know its icon
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2009-11-14 04:58:33 +01:00
|
|
|
Q_INVOKABLE QIcon tabIcon(int index) const;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
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
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param 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
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param stylesheet a CSS string
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
void setStyleSheet(const QString &stylesheet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the stylesheet currently used with this widget
|
|
|
|
*/
|
|
|
|
QString styleSheet() const;
|
|
|
|
|
2011-05-04 13:00:17 +02:00
|
|
|
/**
|
|
|
|
* Highlight the specified tab
|
|
|
|
* @param index of the tab to highlight
|
|
|
|
* @param highlight true if it should be highlighted, wrong if not
|
|
|
|
* @since 4.7
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void setTabHighlighted(int index, bool highlight);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return if the tab at index is highlighted
|
|
|
|
* @since 4.7
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE bool isTabHighlighted(int index) const;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
2010-07-12 10:29:49 +02:00
|
|
|
/**
|
|
|
|
* Set a widget to be displayed on one side of the TabBar, depending on the
|
|
|
|
* LayoutDirection and the Shape.
|
|
|
|
* @param widget the widget to be displayed. Passing 0 will show nothing.
|
|
|
|
* Any previous widget will be deleted.
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
void setFirstPositionWidget(QGraphicsWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the widget in the first position
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
QGraphicsWidget *firstPositionWidget() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a widget to be displayed on one side of the TabBar, depending on the
|
|
|
|
* LayoutDirection and the Shape.
|
|
|
|
* @param widget the widget to be displayed. Passing 0 will show nothing.
|
|
|
|
* Any previous widget will be deleted.
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
void setLastPositionWidget(QGraphicsWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the widget in the last position
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
QGraphicsWidget *lastPositionWidget() const;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Activate a given tab
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the index of the tab to activate
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Emitted when the active tab changes
|
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param index the newly activated tab
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
void currentChanged(int index);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
2008-11-18 16:27:04 +01:00
|
|
|
void resizeEvent(QGraphicsSceneResizeEvent * event);
|
2009-09-13 21:18:29 +02:00
|
|
|
void changeEvent(QEvent *event);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
TabBarPrivate * const d;
|
|
|
|
|
2009-10-29 19:31:27 +01:00
|
|
|
friend class TabBarPrivate;
|
|
|
|
|
2010-01-22 20:31:42 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void slidingNewPageCompleted())
|
|
|
|
Q_PRIVATE_SLOT(d, void slidingOldPageCompleted())
|
2008-11-04 00:08:39 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void shapeChanged(const QTabBar::Shape shape))
|
2009-09-13 21:18:29 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void setPalette())
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|