From e02e4151f3f1fbbf08438fda65f804c2f8e5a48d Mon Sep 17 00:00:00 2001 From: Eike Hein Date: Wed, 1 Oct 2014 18:16:27 +0200 Subject: [PATCH] Add tooltips to the sidebar. BUG:338721 --- appsmodel.cpp | 48 +++++++++++++++++++++++++--------------------- appsmodel.h | 20 ++++++++++--------- favoritesmodel.cpp | 6 +++++- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/appsmodel.cpp b/appsmodel.cpp index 8331a02cc..e20034f34 100644 --- a/appsmodel.cpp +++ b/appsmodel.cpp @@ -53,26 +53,10 @@ AppGroupEntry::AppGroupEntry(KServiceGroup::Ptr group, AppsModel *parentModel, QObject::connect(m_model, SIGNAL(appLaunched(QString)), parentModel, SIGNAL(appLaunched(QString))); } -AppEntry::AppEntry(KService::Ptr service, NameFormat nameFormat) +AppEntry::AppEntry(KService::Ptr service, const QString &name) : m_service(service) { - const QString &name = service->name(); - QString genericName = service->genericName(); - - if (genericName.isEmpty()) { - genericName = service->comment(); - } - - if (nameFormat == NameOnly || genericName.isEmpty() || name == genericName) { - m_name = name; - } else if (nameFormat == GenericNameOnly) { - m_name = genericName; - } else if (nameFormat == NameAndGenericName) { - m_name = i18nc("App name (Generic name)", "%1 (%2)", name, genericName); - } else { - m_name = i18nc("Generic name (App name)", "%1 (%2)", genericName, name); - } - + m_name = name; m_icon = QIcon::fromTheme(service->icon()); m_service = service; } @@ -84,7 +68,7 @@ AppsModel::AppsModel(const QString &entryPath, bool flat, QObject *parent) , m_entryPath(entryPath) , m_changeTimer(0) , m_flat(flat) -, m_appNameFormat(AppEntry::NameOnly) +, m_appNameFormat(NameOnly) , m_sortNeeded(false) , m_appletInterface(0) { @@ -353,8 +337,8 @@ int AppsModel::appNameFormat() const void AppsModel::setAppNameFormat(int format) { - if (m_appNameFormat != (AppEntry::NameFormat)format) { - m_appNameFormat = (AppEntry::NameFormat)format; + if (m_appNameFormat != (NameFormat)format) { + m_appNameFormat = (NameFormat)format; refresh(); @@ -383,6 +367,26 @@ void AppsModel::setAppletInterface(QObject* appletInterface) } } +QString AppsModel::nameFromService(const KService::Ptr service, NameFormat nameFormat) +{ + const QString &name = service->name(); + QString genericName = service->genericName(); + + if (genericName.isEmpty()) { + genericName = service->comment(); + } + + if (nameFormat == NameOnly || genericName.isEmpty() || name == genericName) { + return name; + } else if (nameFormat == GenericNameOnly) { + return genericName; + } else if (nameFormat == NameAndGenericName) { + return i18nc("App name (Generic name)", "%1 (%2)", name, genericName); + } else { + return i18nc("Generic name (App name)", "%1 (%2)", genericName, name); + } +} + void AppsModel::refresh() { beginResetModel(); @@ -472,7 +476,7 @@ void AppsModel::processServiceGroup(KServiceGroup::Ptr group) } if (!found) { - m_entryList << new AppEntry(service, m_appNameFormat); + m_entryList << new AppEntry(service, nameFromService(service, m_appNameFormat)); } } else if (p->isType(KST_KServiceGroup)) { if (m_flat) { diff --git a/appsmodel.h b/appsmodel.h index d78c7d6db..e0c23eb6b 100644 --- a/appsmodel.h +++ b/appsmodel.h @@ -43,14 +43,7 @@ class AppGroupEntry : public AbstractGroupEntry class AppEntry : public AbstractEntry { public: - enum NameFormat { - NameOnly = 0, - GenericNameOnly, - NameAndGenericName, - GenericNameAndName - }; - - AppEntry(KService::Ptr service, NameFormat nameFormat); + AppEntry(KService::Ptr service, const QString &name); EntryType type() const { return RunnableType; } @@ -69,6 +62,13 @@ class AppsModel : public AbstractModel Q_PROPERTY(QObject* appletInterface READ appletInterface WRITE setAppletInterface NOTIFY appletInterfaceChanged); public: + enum NameFormat { + NameOnly = 0, + GenericNameOnly, + NameAndGenericName, + GenericNameAndName + }; + explicit AppsModel(const QString &entryPath = QString(), bool flat = false, QObject *parent = 0); ~AppsModel(); @@ -90,6 +90,8 @@ class AppsModel : public AbstractModel QObject *appletInterface() const; + static QString nameFromService(const KService::Ptr service, NameFormat nameFormat); + public Q_SLOTS: void setAppletInterface(QObject *appletInterface); @@ -115,7 +117,7 @@ class AppsModel : public AbstractModel QString m_entryPath; QTimer *m_changeTimer; bool m_flat; - AppEntry::NameFormat m_appNameFormat; + NameFormat m_appNameFormat; bool m_sortNeeded; QStringList m_hiddenEntries; QObject *m_appletInterface; diff --git a/favoritesmodel.cpp b/favoritesmodel.cpp index 3494a6558..3d69bfd38 100644 --- a/favoritesmodel.cpp +++ b/favoritesmodel.cpp @@ -19,6 +19,7 @@ #include "favoritesmodel.h" #include "actionlist.h" +#include "appsmodel.h" #include @@ -48,7 +49,10 @@ QVariant FavoritesModel::data(const QModelIndex& index, int role) const } else if (m_serviceCache.contains(favoritesId)) { KService::Ptr service = m_serviceCache[favoritesId]; - if (role == Qt::DecorationRole) { + if (role == Qt::DisplayRole) { + return AppsModel::nameFromService(service, + (AppsModel::NameFormat)qobject_cast(parent())->appNameFormat()); + } else if (role == Qt::DecorationRole) { return service->icon(); } else if (role == Kicker::FavoriteIdRole) { return QVariant("app:" + service->storageId());