Commit d8def183 authored by con's avatar con

Give targets a tool tip property.

Use that for showing details about connected Symbian devices.
Also update the icon with an (not-)connected overlay icon.
Graphics design pending.
parent f7207646
......@@ -227,6 +227,8 @@ const char * const SETTINGS_CATEGORY_CORE = "A.Core";
const char * const SETTINGS_TR_CATEGORY_CORE = QT_TRANSLATE_NOOP("Core", "Environment");
const char * const SETTINGS_ID_ENVIRONMENT = "A.General";
const int TARGET_ICON_SIZE = 32;
} // namespace Constants
} // namespace Core
......
......@@ -28,6 +28,7 @@
**************************************************************************/
#include "fancyactionbar.h"
#include "coreconstants.h"
#include <utils/stylehelper.h>
......@@ -98,7 +99,7 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
QRect drawRect = rect();
qDrawBorderPixmap(&painter, drawRect, margins, borderPixmap);
QPixmap pix = icon().pixmap(32, 32, isEnabled() ? QIcon::Normal : QIcon::Disabled);
QPixmap pix = icon().pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE, isEnabled() ? QIcon::Normal : QIcon::Disabled);
QPoint center = rect().center();
QSizeF halfPixSize = pix.size()/2.0;
......
......@@ -35,6 +35,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/mainwindow.h>
#include <coreplugin/coreconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
......@@ -50,6 +51,7 @@
#include <QtGui/QStatusBar>
#include <QtGui/QStackedWidget>
#include <QtGui/QKeyEvent>
#include <QtGui/QPainter>
#include <QtGui/QApplication>
......@@ -135,8 +137,7 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
m_targetName = new QLabel(m_target->displayName());
m_targetName->setObjectName(QLatin1String("target"));
m_targetIcon = new QLabel();
m_targetIcon->setPixmap(m_target->icon().pixmap(48, 48));
updateIcon();
if (hasBuildConfiguration()) {
Q_FOREACH(BuildConfiguration* bc, m_target->buildConfigurations())
addBuildConfiguration(bc);
......@@ -163,6 +164,7 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
SLOT(setActiveRunConfiguration()));
connect(m_target, SIGNAL(iconChanged()), this, SLOT(updateIcon()));
QHBoxLayout *buildHelperLayout = 0;
if (hasBuildConfiguration()) {
......@@ -193,6 +195,24 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
gridLayout->addLayout(formLayout, 1, 0);
}
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);
}
ProjectExplorer::Target *MiniTargetWidget::target() const
{
return m_target;
......@@ -210,6 +230,7 @@ void MiniTargetWidget::setActiveRunConfiguration(int index)
{
m_target->setActiveRunConfiguration(
m_runComboBox->itemData(index).value<ProjectExplorer::RunConfiguration*>());
updateIcon();
emit changed();
}
void MiniTargetWidget::setActiveBuildConfiguration()
......@@ -379,6 +400,8 @@ void MiniProjectTargetSelector::addTarget(ProjectExplorer::Target *target, bool
if (index < 0)
return;
connect(target, SIGNAL(toolTipChanged()), this, SLOT(updateAction()));
connect(target, SIGNAL(iconChanged()), this, SLOT(updateAction()));
ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));
QListWidgetItem *lwi = new QListWidgetItem();
......@@ -426,6 +449,8 @@ void MiniProjectTargetSelector::updateAction()
QString projectName = tr("No Project");
QString targetName;
QString targetToolTipText;
QIcon targetIcon;
QString buildConfig;
QString runConfig;
......@@ -443,18 +468,21 @@ void MiniProjectTargetSelector::updateAction()
if (RunConfiguration *rc = target->activeRunConfiguration()) {
runConfig = rc->displayName();
}
targetToolTipText = target->toolTip();
targetIcon = target->icon();
}
}
m_projectAction->setProperty("heading", projectName);
m_projectAction->setProperty("subtitle", buildConfig);
if (project && project->activeTarget())
m_projectAction->setIcon(project->activeTarget()->icon());
QString toolTip = tr("<html><b>Project:</b> %1<br/>%2%3<b>Run:</b> %4</html>");
m_projectAction->setIcon(targetIcon);
QString toolTip = tr("<html><b>Project:</b> %1<br/>%2%3<b>Run:</b> %4%5</html>");
QString targetTip = targetName.isEmpty() ? QLatin1String("")
: tr("<b>Target:</b> %1<br/>").arg(targetName);
QString buildTip = buildConfig.isEmpty() ? QLatin1String("")
: tr("<b>Build:</b> %2<br/>").arg(buildConfig);
m_projectAction->setToolTip(toolTip.arg(projectName, targetTip, buildTip, runConfig));
QString targetToolTip = targetToolTipText.isEmpty() ? QLatin1String("")
: tr("<br/>%1").arg(targetToolTipText);
m_projectAction->setToolTip(toolTip.arg(projectName, targetTip, buildTip, runConfig, targetToolTip));
}
int MiniProjectTargetSelector::indexFor(ProjectExplorer::Project *project) const
......
......@@ -91,6 +91,7 @@ private slots:
void setActiveRunConfiguration();
void updateDisplayName();
void updateIcon();
signals:
void changed();
......
......@@ -214,6 +214,17 @@ void Target::setIcon(QIcon icon)
emit iconChanged();
}
QString Target::toolTip() const
{
return m_toolTip;
}
void Target::setToolTip(const QString &text)
{
m_toolTip = text;
emit toolTipChanged();
}
QVariantMap Target::toMap() const
{
const QList<BuildConfiguration *> bcs = buildConfigurations();
......
......@@ -82,12 +82,15 @@ public:
QIcon icon() const;
void setIcon(QIcon icon);
QString toolTip() const;
void setToolTip(const QString &text);
virtual QVariantMap toMap() const;
signals:
void targetEnabled(bool);
void iconChanged();
void toolTipChanged();
// TODO clean up signal names
// might be better to also have aboutToRemove signals
......@@ -119,6 +122,7 @@ private:
Project *m_project;
bool m_isEnabled;
QIcon m_icon;
QString m_toolTip;
QList<BuildConfiguration *> m_buildConfigurations;
BuildConfiguration *m_activeBuildConfiguration;
......
......@@ -230,7 +230,11 @@ QString S60DeviceRunConfiguration::serialPortName() const
void S60DeviceRunConfiguration::setSerialPortName(const QString &name)
{
m_serialPortName = name.trimmed();
const QString &candidate = name.trimmed();
if (m_serialPortName == candidate)
return;
m_serialPortName = candidate;
emit serialPortNameChanged();
}
int S60DeviceRunConfiguration::communicationType() const
......
......@@ -75,7 +75,7 @@ public:
QString serialPortName() const;
void setSerialPortName(const QString &name);
// See SerialDeviceListener
// See SymbianDeviceManager
int communicationType() const;
void setCommunicationType(int t);
......@@ -103,6 +103,7 @@ public:
signals:
void targetInformationChanged();
void serialPortNameChanged();
private slots:
void invalidateCachedTargetInformation();
......
......@@ -10,5 +10,7 @@
<file>images/qt_qrc.png</file>
<file>images/sources.png</file>
<file>images/unknown.png</file>
<file>images/connected.png</file>
<file>images/notconnected.png</file>
</qresource>
</RCC>
......@@ -40,8 +40,12 @@
#include "qt-s60/s60emulatorrunconfiguration.h"
#include <projectexplorer/toolchain.h>
#include <coreplugin/coreconstants.h>
#include <symbianutils/symbiandevicemanager.h>
#include <QtGui/QApplication>
#include <QtGui/QPixmap>
#include <QtGui/QPainter>
using namespace ProjectExplorer;
using namespace Qt4ProjectManager;
......@@ -67,13 +71,13 @@ QIcon iconForId(const QString &id) {
if (id == QLatin1String(DESKTOP_TARGET_ID))
return QIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
if (id == QLatin1String(S60_EMULATOR_TARGET_ID))
return QIcon();
return QIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
if (id == QLatin1String(S60_DEVICE_TARGET_ID))
return QIcon();
return QIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
if (id == QLatin1String(MAEMO_EMULATOR_TARGET_ID))
return QIcon();
return QIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
if (id == QLatin1String(MAEMO_DEVICE_TARGET_ID))
return QIcon();
return QIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
return QIcon();
}
......@@ -182,9 +186,13 @@ Qt4Target::Qt4Target(Qt4Project *parent, const QString &id) :
this, SIGNAL(targetInformationChanged()));
connect(this, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SIGNAL(environmentChanged()));
connect(this, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
this, SLOT(onAddedRunConfiguration(ProjectExplorer::RunConfiguration*)));
connect(this, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
this, SLOT(updateToolTipAndIcon()));
setDisplayName(displayNameForId(id));
setIcon(iconForId(id));
updateToolTipAndIcon();
}
Qt4Target::~Qt4Target()
......@@ -385,18 +393,54 @@ void Qt4Target::updateQtVersion()
setEnabled(project()->supportedTargetIds().contains(id()));
}
void Qt4Target::onAddedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
void Qt4Target::onAddedRunConfiguration(ProjectExplorer::RunConfiguration *rc)
{
Q_ASSERT(rc);
S60DeviceRunConfiguration *deviceRc(qobject_cast<S60DeviceRunConfiguration *>(rc));
if (!deviceRc)
return;
connect(deviceRc, SIGNAL(serialPortNameChanged()),
this, SLOT(slotUpdateDeviceInformation()));
}
void Qt4Target::slotUpdateDeviceInformation()
{
Q_ASSERT(bc);
Qt4BuildConfiguration *qt4bc(qobject_cast<Qt4BuildConfiguration *>(bc));
Q_ASSERT(qt4bc);
connect(qt4bc, SIGNAL(targetInformationChanged()),
this, SLOT(changeTargetInformation()));
S60DeviceRunConfiguration *deviceRc(qobject_cast<S60DeviceRunConfiguration *>(sender()));
if (deviceRc && deviceRc == activeRunConfiguration()) {
updateToolTipAndIcon();
}
}
void Qt4Target::changeTargetInformation()
void Qt4Target::updateToolTipAndIcon()
{
ProjectExplorer::BuildConfiguration *bc(qobject_cast<ProjectExplorer::BuildConfiguration *>(sender()));
if (bc && bc == activeBuildConfiguration())
emit targetInformationChanged();
static const QPixmap connected(":/qt4projectmanager/images/connected.png");
static const QPixmap notconnected(":/qt4projectmanager/images/notconnected.png");
S60DeviceRunConfiguration *deviceRc(qobject_cast<S60DeviceRunConfiguration *>(activeRunConfiguration()));
if (!deviceRc) {
setToolTip(QString());
setIcon(iconForId(id()));
} else {
QString friendlyPortName = SymbianUtils::SymbianDeviceManager::instance()->friendlyNameForPort(
deviceRc->serialPortName());
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));
if (!friendlyPortName.isEmpty()) {
// device connected
setToolTip(tr("<b>Device:</b> %1").arg(friendlyPortName));
painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - connected.width(),
connected.height(), connected);
} else {
setToolTip(tr("<b>Device:</b> Not connected"));
painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - notconnected.width(),
notconnected.height(), notconnected);
}
setIcon(QIcon(pixmap));
}
}
......@@ -102,8 +102,9 @@ protected:
private slots:
void updateQtVersion();
void onAddedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc);
void changeTargetInformation();
void onAddedRunConfiguration(ProjectExplorer::RunConfiguration *rc);
void slotUpdateDeviceInformation();
void updateToolTipAndIcon();
private:
Internal::Qt4BuildConfigurationFactory *m_buildConfigurationFactory;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment