Show Tooltips when hovering Aurorae Tabs.

Using the Plasma ToolTipManager to provide the same tooltips as in the tasks applet.
Currently only icons and title are displayed for tabs. Preview will be added as soon
as the tab's WId is exported by KWin core.
Unfortunately the tooltips are missing translucency.
FEATURE: 228436
FIXED-IN: 4.6.0

svn path=/trunk/KDE/kdebase/workspace/; revision=1188226
icc-effect-5.14.5
Martin Gräßlin 2010-10-21 18:19:01 +00:00
parent e5044f2fb5
commit bc5ade425b
5 changed files with 164 additions and 14 deletions

View File

@ -425,11 +425,11 @@ void AuroraeClient::checkTabs(bool force)
while (m_scene->tabCount() > clientGroupItems().count()) {
m_scene->removeLastTab();
}
QStringList captions;
QList<AuroraeTabData> 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());
}

View File

@ -34,12 +34,13 @@
// KDE
#include <KDE/Plasma/FrameSvg>
#include <KDE/Plasma/PaintUtils>
#include <KDE/Plasma/ToolTipManager>
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<AuroraeTab*>(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<AuroraeTab*>(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<AuroraeTab*>(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<AuroraeTab*>(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<AuroraeTab*>(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

View File

@ -22,7 +22,7 @@
#define AURORAE_AURORAESCENE_H
// #include "libaurorae_export.h"
#include <QtGui/QGraphicsScene>
#include <Plasma/Corona>
#include <kdecoration.h>
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<AuroraeTabData> &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<AuroraeTabData> &data);
/**
* Removes the last tab from the list, if there are at least two tabs.
*/

View File

@ -30,6 +30,7 @@
#include <KDE/KGlobalSettings>
#include <KDE/Plasma/FrameSvg>
#include <KDE/Plasma/PaintUtils>
#include <KDE/Plasma/ToolTipManager>
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

View File

@ -22,6 +22,7 @@
#define AURORAE_AURORAETAB_H
#include <QtGui/QGraphicsWidget>
#include <QtGui/QIcon>
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;
};
}