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>
|
||||
|
||||
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::Internal;
|
||||
|
||||
@@ -198,20 +218,7 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
|
||||
|
||||
void MiniTargetWidget::updateIcon()
|
||||
{
|
||||
QPixmap targetPixmap;
|
||||
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);
|
||||
m_targetIcon->setPixmap(createCenteredIcon(m_target->icon(), QIcon()).pixmap(Core::Constants::TARGET_ICON_SIZE));
|
||||
}
|
||||
|
||||
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(iconChanged()), this, SLOT(updateAction()));
|
||||
connect(target, SIGNAL(overlayIconChanged()), this, SLOT(updateAction()));
|
||||
ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));
|
||||
|
||||
QListWidgetItem *lwi = new QListWidgetItem();
|
||||
@@ -456,6 +464,9 @@ void MiniProjectTargetSelector::removeTarget(ProjectExplorer::Target *target)
|
||||
delete plw->takeItem(i);
|
||||
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()
|
||||
@@ -484,7 +495,7 @@ void MiniProjectTargetSelector::updateAction()
|
||||
runConfig = rc->displayName();
|
||||
}
|
||||
targetToolTipText = target->toolTip();
|
||||
targetIcon = target->icon();
|
||||
targetIcon = createCenteredIcon(target->icon(), target->overlayIcon());
|
||||
}
|
||||
}
|
||||
m_projectAction->setProperty("heading", projectName);
|
||||
|
||||
@@ -213,6 +213,17 @@ void Target::setIcon(QIcon icon)
|
||||
emit iconChanged();
|
||||
}
|
||||
|
||||
QIcon Target::overlayIcon() const
|
||||
{
|
||||
return m_overlayIcon;
|
||||
}
|
||||
|
||||
void Target::setOverlayIcon(QIcon icon)
|
||||
{
|
||||
m_overlayIcon = icon;
|
||||
emit overlayIconChanged();
|
||||
}
|
||||
|
||||
QString Target::toolTip() const
|
||||
{
|
||||
return m_toolTip;
|
||||
|
||||
@@ -82,6 +82,8 @@ public:
|
||||
|
||||
QIcon icon() const;
|
||||
void setIcon(QIcon icon);
|
||||
QIcon overlayIcon() const;
|
||||
void setOverlayIcon(QIcon icon);
|
||||
QString toolTip() const;
|
||||
void setToolTip(const QString &text);
|
||||
|
||||
@@ -90,6 +92,7 @@ public:
|
||||
signals:
|
||||
void targetEnabled(bool);
|
||||
void iconChanged();
|
||||
void overlayIconChanged();
|
||||
void toolTipChanged();
|
||||
|
||||
// TODO clean up signal names
|
||||
@@ -122,6 +125,7 @@ private:
|
||||
Project *m_project;
|
||||
bool m_isEnabled;
|
||||
QIcon m_icon;
|
||||
QIcon m_overlayIcon;
|
||||
QString m_toolTip;
|
||||
|
||||
QList<BuildConfiguration *> m_buildConfigurations;
|
||||
|
||||
@@ -218,7 +218,7 @@ Qt4Target::Qt4Target(Qt4Project *parent, const QString &id) :
|
||||
this, SLOT(updateToolTipAndIcon()));
|
||||
|
||||
setDisplayName(displayNameForId(id));
|
||||
updateToolTipAndIcon();
|
||||
setIcon(iconForId(id));
|
||||
}
|
||||
|
||||
Qt4Target::~Qt4Target()
|
||||
@@ -407,7 +407,7 @@ bool Qt4Target::fromMap(const QVariantMap &map)
|
||||
return false;
|
||||
|
||||
setDisplayName(displayNameForId(id()));
|
||||
updateToolTipAndIcon();
|
||||
setIcon(iconForId(id()));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -455,22 +455,14 @@ void Qt4Target::changeTargetInformation()
|
||||
|
||||
void Qt4Target::updateToolTipAndIcon()
|
||||
{
|
||||
static const int TARGET_OVERLAY_ORIGINAL_SIZE = 32;
|
||||
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 int deviceIndex = sdm->findByPortName(s60DeviceRc->serialPortName());
|
||||
QPixmap overlay;
|
||||
if (deviceIndex == -1) {
|
||||
setToolTip(tr("<b>Device:</b> Not connected"));
|
||||
painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - m_disconnectedPixmap.width(),
|
||||
m_disconnectedPixmap.height(), m_disconnectedPixmap);
|
||||
overlay = m_disconnectedPixmap;
|
||||
} else {
|
||||
// device connected
|
||||
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, %2").arg(device.friendlyName(), device.additionalInformation());
|
||||
setToolTip(tooltip);
|
||||
painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - m_connectedPixmap.width(),
|
||||
m_connectedPixmap.height(), m_connectedPixmap);
|
||||
}
|
||||
setIcon(QIcon(pixmap));
|
||||
return;
|
||||
overlay = m_connectedPixmap;
|
||||
}
|
||||
double factor = Core::Constants::TARGET_ICON_SIZE / (double)TARGET_OVERLAY_ORIGINAL_SIZE;
|
||||
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());
|
||||
setIcon(iconForId(id()));
|
||||
setOverlayIcon(QIcon());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user