forked from qt-creator/qt-creator
ProjectExplorer: Offer device icons as kit icons
... in the dialog that lets users choose an icon for their kit. In addition, users can still choose icon files from the file systems. Fixes: QTCREATORBUG-9029 Change-Id: I0ee7d2f532ef637d65ac718b8eaaabe4b81e7fb3 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -60,6 +60,7 @@ const char AUTODETECTIONSOURCE_KEY[] = "PE.Profile.AutoDetectionSource";
|
||||
const char SDK_PROVIDED_KEY[] = "PE.Profile.SDK";
|
||||
const char DATA_KEY[] = "PE.Profile.Data";
|
||||
const char ICON_KEY[] = "PE.Profile.Icon";
|
||||
const char DEVICE_TYPE_FOR_ICON_KEY[] = "PE.Profile.DeviceTypeForIcon";
|
||||
const char MUTABLE_INFO_KEY[] = "PE.Profile.MutableInfo";
|
||||
const char STICKY_INFO_KEY[] = "PE.Profile.StickyInfo";
|
||||
const char IRRELEVANT_ASPECTS_KEY[] = "PE.Kit.IrrelevantAspects";
|
||||
@@ -123,6 +124,7 @@ public:
|
||||
bool m_mustNotify = false;
|
||||
QIcon m_cachedIcon;
|
||||
FileName m_iconPath;
|
||||
Id m_deviceTypeForIcon;
|
||||
|
||||
QHash<Id, QVariant> m_data;
|
||||
QSet<Id> m_sticky;
|
||||
@@ -162,6 +164,7 @@ Kit::Kit(const QVariantMap &data) :
|
||||
d->m_fileSystemFriendlyName = data.value(QLatin1String(FILESYSTEMFRIENDLYNAME_KEY)).toString();
|
||||
d->m_iconPath = FileName::fromString(data.value(QLatin1String(ICON_KEY),
|
||||
d->m_iconPath.toString()).toString());
|
||||
d->m_deviceTypeForIcon = Id::fromSetting(data.value(DEVICE_TYPE_FOR_ICON_KEY));
|
||||
const auto it = data.constFind(IRRELEVANT_ASPECTS_KEY);
|
||||
if (it != data.constEnd())
|
||||
d->m_irrelevantAspects = transform<QSet<Id>>(it.value().toList(), &Id::fromSetting);
|
||||
@@ -210,6 +213,7 @@ Kit *Kit::clone(bool keepName) const
|
||||
k->d->m_hasError = d->m_hasError;
|
||||
k->d->m_cachedIcon = d->m_cachedIcon;
|
||||
k->d->m_iconPath = d->m_iconPath;
|
||||
k->d->m_deviceTypeForIcon = d->m_deviceTypeForIcon;
|
||||
k->d->m_sticky = d->m_sticky;
|
||||
k->d->m_mutable = d->m_mutable;
|
||||
k->d->m_irrelevantAspects = d->m_irrelevantAspects;
|
||||
@@ -221,6 +225,7 @@ void Kit::copyFrom(const Kit *k)
|
||||
KitGuard g(this);
|
||||
d->m_data = k->d->m_data;
|
||||
d->m_iconPath = k->d->m_iconPath;
|
||||
d->m_deviceTypeForIcon = k->d->m_deviceTypeForIcon;
|
||||
d->m_cachedIcon = k->d->m_cachedIcon;
|
||||
d->m_autodetected = k->d->m_autodetected;
|
||||
d->m_autoDetectionSource = k->d->m_autoDetectionSource;
|
||||
@@ -379,12 +384,13 @@ QIcon Kit::icon() const
|
||||
if (!d->m_cachedIcon.isNull())
|
||||
return d->m_cachedIcon;
|
||||
|
||||
if (!d->m_iconPath.isEmpty() && d->m_iconPath.exists()) {
|
||||
if (!d->m_deviceTypeForIcon.isValid() && !d->m_iconPath.isEmpty() && d->m_iconPath.exists()) {
|
||||
d->m_cachedIcon = QIcon(d->m_iconPath.toString());
|
||||
return d->m_cachedIcon;
|
||||
}
|
||||
|
||||
const Core::Id deviceType = DeviceTypeKitAspect::deviceTypeId(this);
|
||||
const Core::Id deviceType = d->m_deviceTypeForIcon.isValid()
|
||||
? d->m_deviceTypeForIcon : DeviceTypeKitAspect::deviceTypeId(this);
|
||||
const QIcon deviceTypeIcon = iconForDeviceType(deviceType);
|
||||
if (!deviceTypeIcon.isNull()) {
|
||||
d->m_cachedIcon = deviceTypeIcon;
|
||||
@@ -404,10 +410,20 @@ void Kit::setIconPath(const FileName &path)
|
||||
{
|
||||
if (d->m_iconPath == path)
|
||||
return;
|
||||
d->m_deviceTypeForIcon = Id();
|
||||
d->m_iconPath = path;
|
||||
kitUpdated();
|
||||
}
|
||||
|
||||
void Kit::setDeviceTypeForIcon(Id deviceType)
|
||||
{
|
||||
if (d->m_deviceTypeForIcon == deviceType)
|
||||
return;
|
||||
d->m_iconPath.clear();
|
||||
d->m_deviceTypeForIcon = deviceType;
|
||||
kitUpdated();
|
||||
}
|
||||
|
||||
QList<Id> Kit::allKeys() const
|
||||
{
|
||||
return d->m_data.keys();
|
||||
@@ -474,6 +490,7 @@ bool Kit::isEqual(const Kit *other) const
|
||||
{
|
||||
return isDataEqual(other)
|
||||
&& d->m_iconPath == other->d->m_iconPath
|
||||
&& d->m_deviceTypeForIcon == other->d->m_deviceTypeForIcon
|
||||
&& d->m_unexpandedDisplayName == other->d->m_unexpandedDisplayName
|
||||
&& d->m_fileSystemFriendlyName == other->d->m_fileSystemFriendlyName
|
||||
&& d->m_irrelevantAspects == other->d->m_irrelevantAspects
|
||||
@@ -493,6 +510,7 @@ QVariantMap Kit::toMap() const
|
||||
data.insert(QLatin1String(AUTODETECTIONSOURCE_KEY), d->m_autoDetectionSource);
|
||||
data.insert(QLatin1String(SDK_PROVIDED_KEY), d->m_sdkProvided);
|
||||
data.insert(QLatin1String(ICON_KEY), d->m_iconPath.toString());
|
||||
data.insert(DEVICE_TYPE_FOR_ICON_KEY, d->m_deviceTypeForIcon.toSetting());
|
||||
|
||||
QStringList mutableInfo;
|
||||
foreach (Id id, d->m_mutable)
|
||||
|
||||
@@ -99,6 +99,7 @@ public:
|
||||
QIcon icon() const;
|
||||
Utils::FileName iconPath() const;
|
||||
void setIconPath(const Utils::FileName &path);
|
||||
void setDeviceTypeForIcon(Core::Id deviceType);
|
||||
|
||||
QList<Core::Id> allKeys() const;
|
||||
QVariant value(Core::Id key, const QVariant &unset = QVariant()) const;
|
||||
|
||||
@@ -24,18 +24,21 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "kitmanagerconfigwidget.h"
|
||||
#include "projectexplorerconstants.h"
|
||||
|
||||
#include "devicesupport/idevicefactory.h"
|
||||
#include "kit.h"
|
||||
#include "kitinformation.h"
|
||||
#include "kitmanager.h"
|
||||
#include "projectexplorerconstants.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <coreplugin/variablechooser.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/detailswidget.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QRegularExpression>
|
||||
@@ -44,6 +47,7 @@
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
@@ -96,7 +100,7 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
|
||||
label = createLabel(tr("Name:"), tr("Kit name and icon."));
|
||||
m_layout->addWidget(label, 0, LabelColumn, alignment);
|
||||
m_iconButton->setToolTip(tr("Kit icon."));
|
||||
auto setIconAction = new QAction(tr("Select Icon File"), this);
|
||||
auto setIconAction = new QAction(tr("Select Icon..."), this);
|
||||
m_iconButton->addAction(setIconAction);
|
||||
auto resetIconAction = new QAction(tr("Reset to Device Default Icon"), this);
|
||||
m_iconButton->addAction(resetIconAction);
|
||||
@@ -311,19 +315,44 @@ void KitManagerConfigWidget::removeKit()
|
||||
|
||||
void KitManagerConfigWidget::setIcon()
|
||||
{
|
||||
const Core::Id deviceType = DeviceTypeKitAspect::deviceTypeId(m_modifiedKit.get());
|
||||
QList<IDeviceFactory *> allDeviceFactories = IDeviceFactory::allDeviceFactories();
|
||||
if (deviceType.isValid()) {
|
||||
const auto less = [deviceType](const IDeviceFactory *f1, const IDeviceFactory *f2) {
|
||||
if (f1->deviceType() == deviceType)
|
||||
return true;
|
||||
if (f2->deviceType() == deviceType)
|
||||
return false;
|
||||
return f1->displayName() < f2->displayName();
|
||||
};
|
||||
Utils::sort(allDeviceFactories, less);
|
||||
}
|
||||
QMenu iconMenu;
|
||||
for (const IDeviceFactory * const factory : qAsConst(allDeviceFactories)) {
|
||||
if (factory->icon().isNull())
|
||||
continue;
|
||||
iconMenu.addAction(factory->icon(), tr("Default for %1").arg(factory->displayName()),
|
||||
[this, factory] {
|
||||
m_iconButton->setIcon(factory->icon());
|
||||
m_modifiedKit->setDeviceTypeForIcon(factory->deviceType());
|
||||
emit dirty();
|
||||
});
|
||||
}
|
||||
iconMenu.addSeparator();
|
||||
iconMenu.addAction(Utils::PathChooser::browseButtonLabel(), [this] {
|
||||
const QString path = QFileDialog::getOpenFileName(this, tr("Select Icon"),
|
||||
m_modifiedKit->iconPath().toString(),
|
||||
tr("Images (*.png *.xpm *.jpg)"));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
const QIcon icon(path);
|
||||
if (icon.isNull())
|
||||
return;
|
||||
|
||||
m_iconButton->setIcon(icon);
|
||||
m_modifiedKit->setIconPath(Utils::FileName::fromString(path));
|
||||
emit dirty();
|
||||
});
|
||||
iconMenu.exec(mapToGlobal(m_iconButton->pos()));
|
||||
}
|
||||
|
||||
void KitManagerConfigWidget::resetIcon()
|
||||
|
||||
Reference in New Issue
Block a user