forked from qt-creator/qt-creator
ExtensionManager: Display extension status
Fixes: QTCREATORBUG-31180 Change-Id: I28c56f2e312670183b21e919ef578135c0384d92 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/extensionmanager">
|
||||
<file>images/checkmark.png</file>
|
||||
<file>images/checkmark@2x.png</file>
|
||||
<file>images/download.png</file>
|
||||
<file>images/download@2x.png</file>
|
||||
<file>images/extensionbig.png</file>
|
||||
|
||||
@@ -59,6 +59,19 @@ constexpr int gapSize = HGapL;
|
||||
constexpr int itemWidth = 330;
|
||||
constexpr int cellWidth = itemWidth + gapSize;
|
||||
|
||||
static QString extensionStateDisplayString(ExtensionState state)
|
||||
{
|
||||
switch (state) {
|
||||
case InstalledEnabled:
|
||||
return Tr::tr("Loaded");
|
||||
case InstalledDisabled:
|
||||
return Tr::tr("Installed");
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
class ExtensionItemDelegate : public QItemDelegate
|
||||
{
|
||||
public:
|
||||
@@ -71,6 +84,8 @@ public:
|
||||
constexpr static TextFormat vendorTF
|
||||
{Theme::Token_Text_Muted, UiElement::UiElementLabelSmall,
|
||||
Qt::AlignVCenter | Qt::TextDontClip};
|
||||
constexpr static TextFormat stateTF
|
||||
{vendorTF.themeColor, UiElement::UiElementCaption, vendorTF.drawTextFlags};
|
||||
constexpr static TextFormat tagsTF
|
||||
{Theme::Token_Text_Default, UiElement::UiElementCaption};
|
||||
|
||||
@@ -84,9 +99,9 @@ public:
|
||||
{
|
||||
// +---------------+-------+---------------+----------------------------------------------------------------------+---------------+---------+
|
||||
// | | | | (ExPaddingGapL) | | |
|
||||
// | | | +-------------------------------------------------------------+--------+ | |
|
||||
// | | | | <itemName> |<status>| | |
|
||||
// | | | +-------------------------------------------------------------+--------+ | |
|
||||
// | | | +-----------------------------+---------+--------+---------+-----------+ | |
|
||||
// | | | | <itemName> |(HGapXxs)|<status>|(HGapXxs)|<checkmark>| | |
|
||||
// | | | +-----------------------------+---------+--------+---------+-----------+ | |
|
||||
// | | | | (VGapXxs) | | |
|
||||
// | | | +--------+--------+--------------+--------+--------+---------+---------+ | |
|
||||
// |(ExPaddingGapL)|<icon> |(ExPaddingGapL)|<vendor>|(HGapXs)|<divider>(h16)|(HGapXs)|<dlIcon>|(HGapXxs)|<dlCount>|(ExPaddingGapL)|(gapSize)|
|
||||
@@ -116,6 +131,19 @@ public:
|
||||
const QRect itemNameR(x, y, middleColumnW, itemNameTF.lineHeight());
|
||||
const QString itemName = index.data().toString();
|
||||
|
||||
const QSize checkmarkS(12, 12);
|
||||
const QRect checkmarkR(x + middleColumnW - checkmarkS.width(), y,
|
||||
checkmarkS.width(), checkmarkS.height());
|
||||
const ExtensionState state = index.data(RoleExtensionState).value<ExtensionState>();
|
||||
const QString stateString = extensionStateDisplayString(state);
|
||||
const bool showState = (state == InstalledEnabled || state == InstalledDisabled)
|
||||
&& !stateString.isEmpty();
|
||||
const QFont stateFont = stateTF.font();
|
||||
const QFontMetrics stateFM(stateFont);
|
||||
const int stateStringWidth = stateFM.horizontalAdvance(stateString);
|
||||
const QRect stateR(checkmarkR.x() - HGapXxs - stateStringWidth, y,
|
||||
stateStringWidth, stateTF.lineHeight());
|
||||
|
||||
y += itemNameR.height() + VGapXxs;
|
||||
const QRect vendorRowR(x, y, middleColumnW, vendorRowHeight());
|
||||
QRect vendorR = vendorRowR;
|
||||
@@ -162,11 +190,22 @@ public:
|
||||
painter->drawText(smallCircle, countTF.drawTextFlags, QString::number(plugins.count()));
|
||||
}
|
||||
{
|
||||
QRect effectiveR = itemNameR;
|
||||
if (showState)
|
||||
effectiveR.setRight(stateR.left() - HGapXxs - 1);
|
||||
painter->setPen(itemNameTF.color());
|
||||
painter->setFont(itemNameTF.font());
|
||||
const QString titleElided
|
||||
= painter->fontMetrics().elidedText(itemName, Qt::ElideRight, itemNameR.width());
|
||||
painter->drawText(itemNameR, itemNameTF.drawTextFlags, titleElided);
|
||||
= painter->fontMetrics().elidedText(itemName, Qt::ElideRight, effectiveR.width());
|
||||
painter->drawText(effectiveR, itemNameTF.drawTextFlags, titleElided);
|
||||
}
|
||||
if (showState) {
|
||||
static const QIcon checkmark = Icon({{":/extensionmanager/images/checkmark.png",
|
||||
stateTF.themeColor}}, Icon::Tint).icon();
|
||||
checkmark.paint(painter, checkmarkR);
|
||||
painter->setPen(stateTF.color());
|
||||
painter->setFont(stateTF.font());
|
||||
painter->drawText(stateR, stateTF.drawTextFlags, stateString);
|
||||
}
|
||||
{
|
||||
const QString vendor = index.data(RoleVendor).toString();
|
||||
|
||||
@@ -358,6 +358,18 @@ static QVariant dataFromExtension(const Extension &extension, int role)
|
||||
return {};
|
||||
}
|
||||
|
||||
ExtensionState extensionState(const QModelIndex &index)
|
||||
{
|
||||
if (index.data(RoleItemType) != ItemTypeExtension)
|
||||
return None;
|
||||
|
||||
const PluginSpec *ps = pluginSpecForName(index.data(RoleName).toString());
|
||||
if (!ps)
|
||||
return NotInstalled;
|
||||
|
||||
return ps->isEffectivelyEnabled() ? InstalledEnabled : InstalledDisabled;
|
||||
}
|
||||
|
||||
static QString searchText(const QModelIndex &index)
|
||||
{
|
||||
QStringList searchTexts;
|
||||
@@ -370,6 +382,8 @@ static QString searchText(const QModelIndex &index)
|
||||
|
||||
QVariant ExtensionsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == RoleExtensionState)
|
||||
return extensionState(index);
|
||||
if (role == RoleSearchText)
|
||||
return searchText(index);
|
||||
|
||||
|
||||
@@ -23,6 +23,13 @@ enum ItemType {
|
||||
ItemTypeExtension,
|
||||
};
|
||||
|
||||
enum ExtensionState {
|
||||
None, // Not a plugin
|
||||
InstalledEnabled,
|
||||
InstalledDisabled,
|
||||
NotInstalled,
|
||||
};
|
||||
|
||||
enum Role {
|
||||
RoleName = Qt::UserRole,
|
||||
RoleCompatVersion,
|
||||
@@ -32,6 +39,7 @@ enum Role {
|
||||
RoleDescriptionLinks,
|
||||
RoleDescriptionText,
|
||||
RoleDownloadCount,
|
||||
RoleExtensionState,
|
||||
RoleId,
|
||||
RoleItemType,
|
||||
RoleLicense,
|
||||
|
||||
BIN
src/plugins/extensionmanager/images/checkmark.png
Normal file
BIN
src/plugins/extensionmanager/images/checkmark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 165 B |
BIN
src/plugins/extensionmanager/images/checkmark@2x.png
Normal file
BIN
src/plugins/extensionmanager/images/checkmark@2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 286 B |
Reference in New Issue
Block a user