diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index 8e693bd105..08431a3544 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -425,11 +425,11 @@ void AuroraeClient::checkTabs(bool force) while (m_scene->tabCount() > clientGroupItems().count()) { m_scene->removeLastTab(); } - QStringList captions; + QList data; foreach (const ClientGroupItem &item, clientGroupItems()) { - captions << item.title(); + data << AuroraeTabData(item.title(), item.icon()); } - m_scene->setCaptions(captions); + m_scene->setAllTabData(data); m_scene->setFocusedTab(visibleClientGroupItem()); } diff --git a/clients/aurorae/src/lib/auroraescene.cpp b/clients/aurorae/src/lib/auroraescene.cpp index 832c27c302..d16aa0cb1f 100644 --- a/clients/aurorae/src/lib/auroraescene.cpp +++ b/clients/aurorae/src/lib/auroraescene.cpp @@ -34,12 +34,13 @@ // KDE #include #include +#include namespace Aurorae { AuroraeScene::AuroraeScene(Aurorae::AuroraeTheme* theme, const QString& leftButtons, const QString& rightButtons, bool contextHelp, QObject* parent) - : QGraphicsScene(parent) + : Plasma::Corona(parent) , m_theme(theme) , m_leftButtons(0) , m_rightButtons(0) @@ -786,13 +787,7 @@ void AuroraeScene::setButtons(const QString &left, const QString &right) void AuroraeScene::setCaption(const QString &caption, int index) { - foreach (QGraphicsItem *item, items()) { - if (AuroraeTab *tab = dynamic_cast(item)) { - if (tab->index() == index) { - tab->setCaption(caption); - } - } - } + setTabData(AuroraeTabData(caption), index); } void AuroraeScene::setCaptions(const QStringList &captions) @@ -806,9 +801,38 @@ void AuroraeScene::setCaptions(const QStringList &captions) } } +void AuroraeScene::setTabData(const AuroraeTabData &data, int index) +{ + foreach (QGraphicsItem *item, items()) { + if (AuroraeTab *tab = dynamic_cast(item)) { + if (tab->index() == index) { + tab->setCaption(data.caption()); + } + } + } +} + +void AuroraeScene::setAllTabData(const QList< AuroraeTabData >& data) +{ + foreach (QGraphicsItem *item, items()) { + if (AuroraeTab *tab = dynamic_cast(item)) { + if (tab->index() < data.size()) { + const AuroraeTabData &datum = data[tab->index()]; + tab->setCaption(datum.caption()); + tab->setIcon(datum.icon()); + } + } + } +} + void AuroraeScene::addTab(const QString &caption) { - AuroraeTab *tab = new AuroraeTab(m_theme, caption, m_tabCount); + addTab(AuroraeTabData(caption)); +} + +void AuroraeScene::addTab(const Aurorae::AuroraeTabData &data) +{ + AuroraeTab *tab = new AuroraeTab(m_theme, data.caption(), m_tabCount); ++m_tabCount; connect(this, SIGNAL(activeChanged()), tab, SLOT(activeChanged())); connect(tab, SIGNAL(mouseButtonPress(QGraphicsSceneMouseEvent*,int)), @@ -824,6 +848,9 @@ void AuroraeScene::addTab(const QString &caption) foreach (QGraphicsItem *item, items()) { if (AuroraeTab *tab = dynamic_cast(item)) { tab->activeChanged(); + if (m_tabCount > 1) { + Plasma::ToolTipManager::self()->registerWidget(tab); + } } } } @@ -835,6 +862,13 @@ void AuroraeScene::addTabs(const QStringList &captions) } } +void AuroraeScene::addTabs(const QList< AuroraeTabData > &data) +{ + foreach (const AuroraeTabData &datum, data) { + addTab(datum); + } +} + void AuroraeScene::removeLastTab() { if (m_tabCount < 2) { @@ -855,6 +889,9 @@ void AuroraeScene::removeLastTab() foreach (QGraphicsItem *item, items()) { if (AuroraeTab *tab = dynamic_cast(item)) { tab->activeChanged(); + if (m_tabCount == 1) { + Plasma::ToolTipManager::self()->unregisterWidget(tab); + } } } } @@ -1055,4 +1092,53 @@ const QString &AuroraeScene::rightButtons() const return m_rightButtonOrder; } +/************************************************* + * AuroraeTabData + ************************************************/ +AuroraeTabData::AuroraeTabData() +{ +} + +AuroraeTabData::AuroraeTabData(const QString& caption) + : m_caption(caption) +{ +} + +AuroraeTabData::AuroraeTabData(const QString &caption, const QIcon &icon, WId wId) + : m_caption(caption) + , m_icon(icon) + , m_wId(wId) +{ +} + +QString AuroraeTabData::caption() const +{ + return m_caption; +} + +QIcon AuroraeTabData::icon() const +{ + return m_icon; +} + +void AuroraeTabData::setCaption(const QString &caption) +{ + m_caption = caption; +} + +void AuroraeTabData::setIcon(const QIcon &icon) +{ + m_icon = icon; +} + +void AuroraeTabData::setWId(WId wid) +{ + m_wId = wid; +} + +WId AuroraeTabData::wId() const +{ + return m_wId; +} + } // namespace diff --git a/clients/aurorae/src/lib/auroraescene.h b/clients/aurorae/src/lib/auroraescene.h index 89cee3ee3c..5446cb91f4 100644 --- a/clients/aurorae/src/lib/auroraescene.h +++ b/clients/aurorae/src/lib/auroraescene.h @@ -22,7 +22,7 @@ #define AURORAE_AURORAESCENE_H // #include "libaurorae_export.h" -#include +#include #include class QGraphicsLayout; @@ -33,7 +33,26 @@ class QPropertyAnimation; namespace Aurorae { class AuroraeTheme; -class /*LIBAURORAE_EXPORT*/ AuroraeScene : public QGraphicsScene +class AuroraeTabData +{ +public: + AuroraeTabData(); + AuroraeTabData(const QString &caption); + AuroraeTabData(const QString &caption, const QIcon &icon, WId wid = 0); + QString caption() const; + void setCaption(const QString &caption); + QIcon icon() const; + void setIcon(const QIcon &icon); + WId wId() const; + void setWId(WId wid); + +private: + QString m_caption; + QIcon m_icon; + WId m_wId; +}; + +class /*LIBAURORAE_EXPORT*/ AuroraeScene : public Plasma::Corona { Q_OBJECT Q_PROPERTY(qreal animation READ animationProgress WRITE setAnimationProgress) @@ -77,14 +96,37 @@ public: * @param captions The new captions */ void setCaptions(const QStringList &captions); + /** + * Updates the tab data for the decoration with given index. + * @param data The new AuroraeTabData + * @param index The index of the tab + * @since 4.6 + */ + void setTabData(const AuroraeTabData &data, int index = 0); + /** + * Updates the tab data for all tabs + * @param data The new AuroraeTabData + * @since 4.6 + */ + void setAllTabData(const QList &data); /** * Adds a tab with given caption to the end of the tab list. */ void addTab(const QString &caption); + /** + * Adds a tab with given tab data to the end of the tab list. + * @since 4.6 + */ + void addTab(const AuroraeTabData &data); /** * Adds a tab for each of the given captions to the end of the tab list. */ void addTabs(const QStringList &captions); + /** + * Adds a tab for each of the given AuroraeTabData to the end of the tab list. + * @since 4.6 + */ + void addTabs(const QList &data); /** * Removes the last tab from the list, if there are at least two tabs. */ diff --git a/clients/aurorae/src/lib/auroraetab.cpp b/clients/aurorae/src/lib/auroraetab.cpp index eeb4a717cb..2f09ba73aa 100644 --- a/clients/aurorae/src/lib/auroraetab.cpp +++ b/clients/aurorae/src/lib/auroraetab.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace Aurorae { @@ -48,6 +49,7 @@ AuroraeTab::AuroraeTab(AuroraeTheme* theme, const QString& caption, int index) if (m_theme->themeConfig().useTextShadow()) { setGraphicsEffect(m_effect); } + setAcceptHoverEvents(true); connect(m_theme, SIGNAL(buttonSizesChanged()), SLOT(buttonSizesChanged())); } @@ -88,6 +90,11 @@ void AuroraeTab::setCaption(const QString& caption) update(); } +void AuroraeTab::setIcon(const QIcon &icon) +{ + m_icon = icon; +} + void AuroraeTab::setIndex(int index) { m_index = index; @@ -297,4 +304,14 @@ void AuroraeTab::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } +void AuroraeTab::toolTipAboutToShow() +{ + Plasma::ToolTipContent data; + data.setMainText(m_caption); + if (!m_icon.isNull()) { + data.setImage(m_icon); + } + Plasma::ToolTipManager::self()->setContent(this, data); +} + } // namespace diff --git a/clients/aurorae/src/lib/auroraetab.h b/clients/aurorae/src/lib/auroraetab.h index 81d20a688e..b5104f8bad 100644 --- a/clients/aurorae/src/lib/auroraetab.h +++ b/clients/aurorae/src/lib/auroraetab.h @@ -22,6 +22,7 @@ #define AURORAE_AURORAETAB_H #include +#include class QGraphicsDropShadowEffect; namespace Aurorae { @@ -35,6 +36,7 @@ public: virtual ~AuroraeTab(); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void setCaption(const QString &caption); + void setIcon(const QIcon &icon); void setIndex(int index); int index() const { return m_index; @@ -49,6 +51,7 @@ Q_SIGNALS: public Q_SLOTS: void activeChanged(); + void toolTipAboutToShow(); protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -69,6 +72,8 @@ private: long int m_uid; bool m_dragAllowed; bool m_clickInProgress; + QIcon m_icon; + WId m_winId; }; }