Welcompage: allow highlighting of demos and examples

With this patch the attribute isHighlighted="true" in
the manifest.xml allows highlighting demos and examples.

The highlighted demos and examples appear first in the list
and have a blue highlight.

Task-number: QTCREATORBUG-8459
Change-Id: Ieeb888630235e07b1ae1398c5ccdc3d7e8d15dff
Reviewed-by: Alessandro Portale <alessandro.portale@digia.com>
This commit is contained in:
Thomas Hartmann
2013-02-04 10:16:02 +01:00
parent a6c8628c12
commit 1d14e7e439
3 changed files with 42 additions and 5 deletions

View File

@@ -35,6 +35,18 @@ Rectangle {
height: 240 height: 240
width: 216 width: 216
Rectangle {
id: highlight
radius: 6
visible: isHighlighted
color: colors.strongForegroundColor
anchors.fill: parent
anchors.topMargin: 2
anchors.leftMargin: 4
anchors.rightMargin: 4
anchors.bottomMargin: 73
}
property alias caption: captionItem.text property alias caption: captionItem.text
property alias imageSource: imageItem.source property alias imageSource: imageItem.source
property alias videoSource: videoIcon.source property alias videoSource: videoIcon.source
@@ -201,11 +213,11 @@ Rectangle {
Rectangle { Rectangle {
id: border id: border
color: "#00000000" color: "#00000000"
radius: 8 radius: 6
anchors.rightMargin: 4 anchors.rightMargin: 4
anchors.leftMargin: 4 anchors.leftMargin: 4
anchors.bottomMargin: 4 anchors.bottomMargin: 4
anchors.topMargin: 4 anchors.topMargin: 1
visible: false visible: false
anchors.fill: parent anchors.fill: parent
border.color: "#dddcdc" border.color: "#dddcdc"
@@ -276,6 +288,11 @@ Rectangle {
target: border target: border
visible: true visible: true
} }
PropertyChanges {
target: highlight
opacity: 0
}
} }
] ]

View File

@@ -167,6 +167,7 @@ ExamplesListModel::ExamplesListModel(QObject *parent) :
roleNames[VideoUrl] = "videoUrl"; roleNames[VideoUrl] = "videoUrl";
roleNames[VideoLength] = "videoLength"; roleNames[VideoLength] = "videoLength";
roleNames[Platforms] = "platforms"; roleNames[Platforms] = "platforms";
roleNames[IsHighlighted] = "isHighlighted";
setRoleNames(roleNames); setRoleNames(roleNames);
connect(Core::HelpManager::instance(), SIGNAL(setupFinished()), connect(Core::HelpManager::instance(), SIGNAL(setupFinished()),
@@ -261,6 +262,10 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, examplesInstallPath); item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, examplesInstallPath);
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString(); item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString(); item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
if (attributes.hasAttribute(QLatin1String("isHighlighted")))
item.isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true");
} else if (reader->name() == QLatin1String("fileToOpen")) { } else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement), item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
projectsOffset, examplesInstallPath)); projectsOffset, examplesInstallPath));
@@ -307,6 +312,10 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, demosInstallPath); item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, demosInstallPath);
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString(); item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString(); item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
if (attributes.hasAttribute(QLatin1String("isHighlighted")))
item.isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true");
} else if (reader->name() == QLatin1String("fileToOpen")) { } else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement), item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
projectsOffset, demosInstallPath)); projectsOffset, demosInstallPath));
@@ -578,6 +587,13 @@ int ExamplesListModel::rowCount(const QModelIndex &) const
return m_exampleItems.size(); return m_exampleItems.size();
} }
QString prefixForItem(const ExampleItem &item)
{
if (item.isHighlighted)
return QLatin1String("0000 ");
return QString();
}
QVariant ExamplesListModel::data(const QModelIndex &index, int role) const QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
{ {
ensureInitialized(); ensureInitialized();
@@ -590,7 +606,7 @@ QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
switch (role) switch (role)
{ {
case Qt::DisplayRole: // for search only case Qt::DisplayRole: // for search only
return QString(item.name + QLatin1Char(' ') + item.tags.join(QLatin1String(" "))); return QString(prefixForItem(item) + item.name + QLatin1Char(' ') + item.tags.join(QLatin1String(" ")));
case Name: case Name:
return item.name; return item.name;
case ProjectPath: case ProjectPath:
@@ -621,6 +637,8 @@ QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
return item.videoLength; return item.videoLength;
case Platforms: case Platforms:
return item.platforms; return item.platforms;
case IsHighlighted:
return item.isHighlighted;
default: default:
qDebug() << Q_FUNC_INFO << "role type not supported"; qDebug() << Q_FUNC_INFO << "role type not supported";
return QVariant(); return QVariant();

View File

@@ -44,7 +44,8 @@ enum ExampleRoles
{ {
Name = Qt::UserRole, ProjectPath, Description, ImageUrl, Name = Qt::UserRole, ProjectPath, Description, ImageUrl,
DocUrl, FilesToOpen, Tags, Difficulty, HasSourceCode, DocUrl, FilesToOpen, Tags, Difficulty, HasSourceCode,
Type, Dependencies, IsVideo, VideoUrl, VideoLength, Platforms Type, Dependencies, IsVideo, VideoUrl, VideoLength, Platforms,
IsHighlighted
}; };
enum InstructionalType enum InstructionalType
@@ -54,7 +55,7 @@ enum InstructionalType
struct ExampleItem struct ExampleItem
{ {
ExampleItem(): difficulty(0), isVideo(false) {} ExampleItem(): difficulty(0), isVideo(false), isHighlighted(false) {}
InstructionalType type; InstructionalType type;
QString name; QString name;
QString projectPath; QString projectPath;
@@ -70,6 +71,7 @@ struct ExampleItem
QString videoUrl; QString videoUrl;
QString videoLength; QString videoLength;
QStringList platforms; QStringList platforms;
bool isHighlighted;
}; };
class ExamplesListModel : public QAbstractListModel class ExamplesListModel : public QAbstractListModel