summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorcon <qtc-committer@nokia.com>2010-02-23 16:52:03 +0100
committercon <qtc-committer@nokia.com>2010-02-23 16:52:44 +0100
commit04d90d9563f347af36db08602535da66ed1963aa (patch)
treea0b42f895ba5d7993c549b918ca346b1e1d716c3 /src/plugins
parentc3578f307db440ffb8c9fc115757c0dcd4ef2c92 (diff)
downloadqt-creator-04d90d9563f347af36db08602535da66ed1963aa.tar.gz
Show target overlay icon only in the active target button.
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/projectexplorer/miniprojecttargetselector.cpp41
-rw-r--r--src/plugins/projectexplorer/target.cpp11
-rw-r--r--src/plugins/projectexplorer/target.h4
-rw-r--r--src/plugins/qt4projectmanager/qt4target.cpp38
4 files changed, 60 insertions, 34 deletions
diff --git a/src/plugins/projectexplorer/miniprojecttargetselector.cpp b/src/plugins/projectexplorer/miniprojecttargetselector.cpp
index 64f81901f5..6994391dca 100644
--- a/src/plugins/projectexplorer/miniprojecttargetselector.cpp
+++ b/src/plugins/projectexplorer/miniprojecttargetselector.cpp
@@ -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);
diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp
index 9e47439c93..9277d350f1 100644
--- a/src/plugins/projectexplorer/target.cpp
+++ b/src/plugins/projectexplorer/target.cpp
@@ -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;
diff --git a/src/plugins/projectexplorer/target.h b/src/plugins/projectexplorer/target.h
index e06eae8226..c18c8cac27 100644
--- a/src/plugins/projectexplorer/target.h
+++ b/src/plugins/projectexplorer/target.h
@@ -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;
diff --git a/src/plugins/qt4projectmanager/qt4target.cpp b/src/plugins/qt4projectmanager/qt4target.cpp
index 36c09cb8fa..b874c903e1 100644
--- a/src/plugins/qt4projectmanager/qt4target.cpp
+++ b/src/plugins/qt4projectmanager/qt4target.cpp
@@ -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);
+ overlay = m_connectedPixmap;
}
- setIcon(QIcon(pixmap));
- return;
+ 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());
+ setOverlayIcon(QIcon());
}
- setToolTip(QString());
- setIcon(iconForId(id()));
}