forked from qt-creator/qt-creator
ProjectExplorer: Enable tooltips in MiniProjectTargetSelector
Enable support for tooltips in MiniProjectTargetSelector. Use it to display the kit information when hovering the Kit selection area. Change-Id: Ie9691973cb74e25217635dc0a798dd9c6219ad37 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -60,7 +60,6 @@
|
||||
#include <QAction>
|
||||
#include <QItemDelegate>
|
||||
|
||||
|
||||
static QIcon createCenteredIcon(const QIcon &icon, const QIcon &overlay)
|
||||
{
|
||||
QPixmap targetPixmap;
|
||||
@@ -154,7 +153,8 @@ void TargetSelectorDelegate::paint(QPainter *painter,
|
||||
if (elidedText != text)
|
||||
const_cast<QAbstractItemModel *>(index.model())->setData(index, text, Qt::ToolTipRole);
|
||||
else
|
||||
const_cast<QAbstractItemModel *>(index.model())->setData(index, QString(), Qt::ToolTipRole);
|
||||
const_cast<QAbstractItemModel *>(index.model())
|
||||
->setData(index, index.model()->data(index, Qt::UserRole + 1).toString(), Qt::ToolTipRole);
|
||||
painter->drawText(option.rect.left() + 6, option.rect.top() + (option.rect.height() - fm.height()) / 2 + fm.ascent(), elidedText);
|
||||
|
||||
painter->restore();
|
||||
@@ -405,6 +405,7 @@ void GenericListWidget::setProjectConfigurations(const QList<ProjectConfiguratio
|
||||
{
|
||||
m_ignoreIndexChange = true;
|
||||
clear();
|
||||
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
ProjectConfiguration *p = item(i)->data(Qt::UserRole).value<ProjectConfiguration *>();
|
||||
disconnect(p, &ProjectConfiguration::displayNameChanged,
|
||||
@@ -432,8 +433,10 @@ void GenericListWidget::setActiveProjectConfiguration(ProjectConfiguration *acti
|
||||
void GenericListWidget::addProjectConfiguration(ProjectConfiguration *pc)
|
||||
{
|
||||
m_ignoreIndexChange = true;
|
||||
QListWidgetItem *lwi = new QListWidgetItem();
|
||||
auto lwi = new QListWidgetItem();
|
||||
lwi->setText(pc->displayName());
|
||||
lwi->setData(Qt::ToolTipRole, pc->toolTip());
|
||||
lwi->setData(Qt::UserRole + 1, pc->toolTip());
|
||||
lwi->setData(Qt::UserRole, QVariant::fromValue(pc));
|
||||
|
||||
// Figure out pos
|
||||
@@ -449,11 +452,13 @@ void GenericListWidget::addProjectConfiguration(ProjectConfiguration *pc)
|
||||
|
||||
connect(pc, &ProjectConfiguration::displayNameChanged,
|
||||
this, &GenericListWidget::displayNameChanged);
|
||||
connect(pc, &ProjectConfiguration::toolTipChanged, this, &GenericListWidget::toolTipChanged);
|
||||
|
||||
QFontMetrics fn(font());
|
||||
int width = fn.width(pc->displayName()) + padding();
|
||||
if (width > optimalWidth())
|
||||
setOptimalWidth(width);
|
||||
|
||||
m_ignoreIndexChange = false;
|
||||
}
|
||||
|
||||
@@ -528,6 +533,15 @@ void GenericListWidget::displayNameChanged()
|
||||
m_ignoreIndexChange = false;
|
||||
}
|
||||
|
||||
void GenericListWidget::toolTipChanged()
|
||||
{
|
||||
ProjectConfiguration *pc = qobject_cast<ProjectConfiguration *>(sender());
|
||||
if (QListWidgetItem *lwi = itemForProjectConfiguration(pc)) {
|
||||
lwi->setData(Qt::ToolTipRole, pc->toolTip());
|
||||
lwi->setData(Qt::UserRole + 1, pc->toolTip());
|
||||
}
|
||||
}
|
||||
|
||||
QListWidgetItem *GenericListWidget::itemForProjectConfiguration(ProjectConfiguration *pc)
|
||||
{
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
@@ -667,7 +681,7 @@ MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorActi
|
||||
|
||||
m_listWidgets.resize(LAST);
|
||||
m_titleWidgets.resize(LAST);
|
||||
m_listWidgets[PROJECT] = 0; //project is not a generic list widget
|
||||
m_listWidgets[PROJECT] = nullptr; //project is not a generic list widget
|
||||
|
||||
m_titleWidgets[PROJECT] = createTitleLabel(tr("Project"));
|
||||
m_projectListWidget = new ProjectListWidget(this);
|
||||
@@ -726,7 +740,6 @@ bool MiniProjectTargetSelector::event(QEvent *event)
|
||||
}
|
||||
}
|
||||
return QWidget::event(event);
|
||||
|
||||
}
|
||||
|
||||
// does some fancy calculations to ensure proper widths for the list widgets
|
||||
@@ -1512,7 +1525,7 @@ void MiniProjectTargetSelector::updateActionAndSummary()
|
||||
if (RunConfiguration *rc = target->activeRunConfiguration())
|
||||
runConfig = rc->displayName();
|
||||
|
||||
targetToolTipText = target->toolTip();
|
||||
targetToolTipText = target->overlayIconToolTip();
|
||||
targetIcon = createCenteredIcon(target->icon(), target->overlayIcon());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user