forked from qt-creator/qt-creator
Show target overlay icon only in the active target button.
This commit is contained in:
@@ -55,6 +55,26 @@
|
|||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
|
|
||||||
|
static QIcon createCenteredIcon(const QIcon &icon, const QIcon &overlay)
|
||||||
|
{
|
||||||
|
QPixmap targetPixmap;
|
||||||
|
targetPixmap = QPixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
|
||||||
|
targetPixmap.fill(Qt::transparent);
|
||||||
|
QPainter painter(&targetPixmap);
|
||||||
|
|
||||||
|
QSize actualSize = icon.actualSize(QSize(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE));
|
||||||
|
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - actualSize.width())/2,
|
||||||
|
(Core::Constants::TARGET_ICON_SIZE - actualSize.height())/2,
|
||||||
|
icon.pixmap(Core::Constants::TARGET_ICON_SIZE));
|
||||||
|
if (!overlay.isNull()) {
|
||||||
|
actualSize = overlay.actualSize(QSize(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE));
|
||||||
|
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - actualSize.width())/2,
|
||||||
|
(Core::Constants::TARGET_ICON_SIZE - actualSize.height())/2,
|
||||||
|
overlay.pixmap(Core::Constants::TARGET_ICON_SIZE));
|
||||||
|
}
|
||||||
|
return QIcon(targetPixmap);
|
||||||
|
}
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace ProjectExplorer::Internal;
|
using namespace ProjectExplorer::Internal;
|
||||||
|
|
||||||
@@ -198,20 +218,7 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
|
|||||||
|
|
||||||
void MiniTargetWidget::updateIcon()
|
void MiniTargetWidget::updateIcon()
|
||||||
{
|
{
|
||||||
QPixmap targetPixmap;
|
m_targetIcon->setPixmap(createCenteredIcon(m_target->icon(), QIcon()).pixmap(Core::Constants::TARGET_ICON_SIZE));
|
||||||
QPixmap targetPixmapCandidate = m_target->icon().pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
|
|
||||||
QSize actualSize = m_target->icon().actualSize(QSize(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE));
|
|
||||||
if (actualSize == QSize(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE)) {
|
|
||||||
targetPixmap = targetPixmapCandidate;
|
|
||||||
} else {
|
|
||||||
targetPixmap = QPixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
|
|
||||||
targetPixmap.fill(Qt::transparent);
|
|
||||||
QPainter painter(&targetPixmap);
|
|
||||||
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - actualSize.width())/2,
|
|
||||||
(Core::Constants::TARGET_ICON_SIZE - actualSize.height())/2,
|
|
||||||
targetPixmapCandidate);
|
|
||||||
}
|
|
||||||
m_targetIcon->setPixmap(targetPixmap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::Target *MiniTargetWidget::target() const
|
ProjectExplorer::Target *MiniTargetWidget::target() const
|
||||||
@@ -404,6 +411,7 @@ void MiniProjectTargetSelector::addTarget(ProjectExplorer::Target *target, bool
|
|||||||
|
|
||||||
connect(target, SIGNAL(toolTipChanged()), this, SLOT(updateAction()));
|
connect(target, SIGNAL(toolTipChanged()), this, SLOT(updateAction()));
|
||||||
connect(target, SIGNAL(iconChanged()), this, SLOT(updateAction()));
|
connect(target, SIGNAL(iconChanged()), this, SLOT(updateAction()));
|
||||||
|
connect(target, SIGNAL(overlayIconChanged()), this, SLOT(updateAction()));
|
||||||
ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));
|
ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));
|
||||||
|
|
||||||
QListWidgetItem *lwi = new QListWidgetItem();
|
QListWidgetItem *lwi = new QListWidgetItem();
|
||||||
@@ -456,6 +464,9 @@ void MiniProjectTargetSelector::removeTarget(ProjectExplorer::Target *target)
|
|||||||
delete plw->takeItem(i);
|
delete plw->takeItem(i);
|
||||||
delete mtw;
|
delete mtw;
|
||||||
}
|
}
|
||||||
|
disconnect(target, SIGNAL(toolTipChanged()), this, SLOT(updateAction()));
|
||||||
|
disconnect(target, SIGNAL(iconChanged()), this, SLOT(updateAction()));
|
||||||
|
disconnect(target, SIGNAL(overlayIconChanged()), this, SLOT(updateAction()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiniProjectTargetSelector::updateAction()
|
void MiniProjectTargetSelector::updateAction()
|
||||||
@@ -484,7 +495,7 @@ void MiniProjectTargetSelector::updateAction()
|
|||||||
runConfig = rc->displayName();
|
runConfig = rc->displayName();
|
||||||
}
|
}
|
||||||
targetToolTipText = target->toolTip();
|
targetToolTipText = target->toolTip();
|
||||||
targetIcon = target->icon();
|
targetIcon = createCenteredIcon(target->icon(), target->overlayIcon());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_projectAction->setProperty("heading", projectName);
|
m_projectAction->setProperty("heading", projectName);
|
||||||
|
|||||||
@@ -213,6 +213,17 @@ void Target::setIcon(QIcon icon)
|
|||||||
emit iconChanged();
|
emit iconChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QIcon Target::overlayIcon() const
|
||||||
|
{
|
||||||
|
return m_overlayIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Target::setOverlayIcon(QIcon icon)
|
||||||
|
{
|
||||||
|
m_overlayIcon = icon;
|
||||||
|
emit overlayIconChanged();
|
||||||
|
}
|
||||||
|
|
||||||
QString Target::toolTip() const
|
QString Target::toolTip() const
|
||||||
{
|
{
|
||||||
return m_toolTip;
|
return m_toolTip;
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ public:
|
|||||||
|
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
void setIcon(QIcon icon);
|
void setIcon(QIcon icon);
|
||||||
|
QIcon overlayIcon() const;
|
||||||
|
void setOverlayIcon(QIcon icon);
|
||||||
QString toolTip() const;
|
QString toolTip() const;
|
||||||
void setToolTip(const QString &text);
|
void setToolTip(const QString &text);
|
||||||
|
|
||||||
@@ -90,6 +92,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void targetEnabled(bool);
|
void targetEnabled(bool);
|
||||||
void iconChanged();
|
void iconChanged();
|
||||||
|
void overlayIconChanged();
|
||||||
void toolTipChanged();
|
void toolTipChanged();
|
||||||
|
|
||||||
// TODO clean up signal names
|
// TODO clean up signal names
|
||||||
@@ -122,6 +125,7 @@ private:
|
|||||||
Project *m_project;
|
Project *m_project;
|
||||||
bool m_isEnabled;
|
bool m_isEnabled;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
|
QIcon m_overlayIcon;
|
||||||
QString m_toolTip;
|
QString m_toolTip;
|
||||||
|
|
||||||
QList<BuildConfiguration *> m_buildConfigurations;
|
QList<BuildConfiguration *> m_buildConfigurations;
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ Qt4Target::Qt4Target(Qt4Project *parent, const QString &id) :
|
|||||||
this, SLOT(updateToolTipAndIcon()));
|
this, SLOT(updateToolTipAndIcon()));
|
||||||
|
|
||||||
setDisplayName(displayNameForId(id));
|
setDisplayName(displayNameForId(id));
|
||||||
updateToolTipAndIcon();
|
setIcon(iconForId(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt4Target::~Qt4Target()
|
Qt4Target::~Qt4Target()
|
||||||
@@ -407,7 +407,7 @@ bool Qt4Target::fromMap(const QVariantMap &map)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
setDisplayName(displayNameForId(id()));
|
setDisplayName(displayNameForId(id()));
|
||||||
updateToolTipAndIcon();
|
setIcon(iconForId(id()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -455,22 +455,14 @@ void Qt4Target::changeTargetInformation()
|
|||||||
|
|
||||||
void Qt4Target::updateToolTipAndIcon()
|
void Qt4Target::updateToolTipAndIcon()
|
||||||
{
|
{
|
||||||
|
static const int TARGET_OVERLAY_ORIGINAL_SIZE = 32;
|
||||||
if (const S60DeviceRunConfiguration *s60DeviceRc = qobject_cast<S60DeviceRunConfiguration *>(activeRunConfiguration())) {
|
if (const S60DeviceRunConfiguration *s60DeviceRc = qobject_cast<S60DeviceRunConfiguration *>(activeRunConfiguration())) {
|
||||||
QPixmap pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
|
|
||||||
pixmap.fill(Qt::transparent);
|
|
||||||
QPainter painter(&pixmap);
|
|
||||||
const QIcon &icon = iconForId(id());
|
|
||||||
QSize actualSize = icon.actualSize(QSize(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE));
|
|
||||||
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE-actualSize.width())/2,
|
|
||||||
(Core::Constants::TARGET_ICON_SIZE-actualSize.height())/2,
|
|
||||||
icon.pixmap(Core::Constants::TARGET_ICON_SIZE));
|
|
||||||
|
|
||||||
const SymbianUtils::SymbianDeviceManager *sdm = SymbianUtils::SymbianDeviceManager::instance();
|
const SymbianUtils::SymbianDeviceManager *sdm = SymbianUtils::SymbianDeviceManager::instance();
|
||||||
const int deviceIndex = sdm->findByPortName(s60DeviceRc->serialPortName());
|
const int deviceIndex = sdm->findByPortName(s60DeviceRc->serialPortName());
|
||||||
|
QPixmap overlay;
|
||||||
if (deviceIndex == -1) {
|
if (deviceIndex == -1) {
|
||||||
setToolTip(tr("<b>Device:</b> Not connected"));
|
setToolTip(tr("<b>Device:</b> Not connected"));
|
||||||
painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - m_disconnectedPixmap.width(),
|
overlay = m_disconnectedPixmap;
|
||||||
m_disconnectedPixmap.height(), m_disconnectedPixmap);
|
|
||||||
} else {
|
} else {
|
||||||
// device connected
|
// device connected
|
||||||
const SymbianUtils::SymbianDevice device = sdm->devices().at(deviceIndex);
|
const SymbianUtils::SymbianDevice device = sdm->devices().at(deviceIndex);
|
||||||
@@ -478,12 +470,20 @@ void Qt4Target::updateToolTipAndIcon()
|
|||||||
tr("<b>Device:</b> %1").arg(device.friendlyName()) :
|
tr("<b>Device:</b> %1").arg(device.friendlyName()) :
|
||||||
tr("<b>Device:</b> %1, %2").arg(device.friendlyName(), device.additionalInformation());
|
tr("<b>Device:</b> %1, %2").arg(device.friendlyName(), device.additionalInformation());
|
||||||
setToolTip(tooltip);
|
setToolTip(tooltip);
|
||||||
painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - m_connectedPixmap.width(),
|
overlay = m_connectedPixmap;
|
||||||
m_connectedPixmap.height(), m_connectedPixmap);
|
|
||||||
}
|
}
|
||||||
setIcon(QIcon(pixmap));
|
double factor = Core::Constants::TARGET_ICON_SIZE / (double)TARGET_OVERLAY_ORIGINAL_SIZE;
|
||||||
return;
|
QSize overlaySize(overlay.size().width()*factor, overlay.size().height()*factor);
|
||||||
|
QPixmap pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - overlaySize.width(),
|
||||||
|
Core::Constants::TARGET_ICON_SIZE - overlaySize.height(),
|
||||||
|
overlay.scaled(overlaySize));
|
||||||
|
|
||||||
|
setOverlayIcon(QIcon(pixmap));
|
||||||
|
} else {
|
||||||
|
setToolTip(QString());
|
||||||
|
setOverlayIcon(QIcon());
|
||||||
}
|
}
|
||||||
setToolTip(QString());
|
|
||||||
setIcon(iconForId(id()));
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user