Add tooltips to the sidebar.

BUG:338721
wilder-5.17
Eike Hein 12 years ago
parent 438c5faee5
commit e02e4151f3
  1. 48
      appsmodel.cpp
  2. 20
      appsmodel.h
  3. 6
      favoritesmodel.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) {

@ -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;

@ -19,6 +19,7 @@
#include "favoritesmodel.h"
#include "actionlist.h"
#include "appsmodel.h"
#include <KRun>
@ -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<AppsModel *>(parent())->appNameFormat());
} else if (role == Qt::DecorationRole) {
return service->icon();
} else if (role == Kicker::FavoriteIdRole) {
return QVariant("app:" + service->storageId());

Loading…
Cancel
Save