Commit 61cf2d0a authored by Jens Bache-Wiig's avatar Jens Bache-Wiig
Browse files

Fix issues with long project names in the minitargetselector

It's impossible to use very long names and some clipping
occurs due to incorrect size hints on QLabel.
- Made the popup minimum width depend on the longest
project name entered. (it will not shrink)
- The build and run labels have increased minimum size hints.
- Combobox tooltip will be set to the project name as to
  make it possible to expand long names.

Task-number: QTCREATORBUG-1278
RevBy: joao
parent 076c0349
......@@ -252,15 +252,19 @@ MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
QFormLayout *formLayout = new QFormLayout;
formLayout->setLabelAlignment(Qt::AlignRight);
QLabel *lbl;
int indent = 10;
if (hasBuildConfiguration()) {
lbl = new QLabel(tr("Build:"));
lbl->setObjectName(QString::fromUtf8("buildLabel"));
lbl->setIndent(10);
lbl->setMinimumWidth(lbl->fontMetrics().width(lbl->text()) + indent + 4);
lbl->setIndent(indent);
formLayout->addRow(lbl, buildHelperLayout);
}
lbl = new QLabel(tr("Run:"));
lbl->setObjectName(QString::fromUtf8("runLabel"));
lbl->setIndent(10);
lbl->setMinimumWidth(lbl->fontMetrics().width(lbl->text()) + indent + 4);
lbl->setIndent(indent);
formLayout->addRow(lbl, runHelperLayout);
gridLayout->addWidget(m_targetName, 0, 0);
......@@ -310,6 +314,8 @@ void MiniTargetWidget::addRunConfiguration(ProjectExplorer::RunConfiguration* rc
{
connect(rc, SIGNAL(displayNameChanged()), SLOT(updateDisplayName()));
m_runComboBox->addItem(rc->displayName(), QVariant::fromValue(rc));
m_runComboBox->setItemData(m_runComboBox->findText(rc->displayName()),
rc->displayName(), Qt::ToolTipRole);
if (m_target->activeRunConfiguration() == rc)
m_runComboBox->setCurrentIndex(m_runComboBox->count()-1);
......@@ -327,6 +333,8 @@ void MiniTargetWidget::addBuildConfiguration(ProjectExplorer::BuildConfiguration
QTC_ASSERT(m_buildComboBox, return);
connect(bc, SIGNAL(displayNameChanged()), SLOT(updateDisplayName()));
m_buildComboBox->addItem(bc->displayName(), QVariant::fromValue(bc));
m_buildComboBox->setItemData(m_buildComboBox->findText(bc->displayName()),
bc->displayName(), Qt::ToolTipRole);
if (m_target->activeBuildConfiguration() == bc)
m_buildComboBox->setCurrentIndex(m_buildComboBox->count()-1);
......@@ -401,7 +409,6 @@ MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorActi
m_projectsBox->setProperty("hideborder", true);
m_projectsBox->setObjectName(QString::fromUtf8("ProjectsBox"));
m_projectsBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
m_projectsBox->setMaximumWidth(200);
toolLayout->addWidget(lbl);
toolLayout->addWidget(new Utils::StyledSeparator);
......@@ -576,6 +583,10 @@ void MiniProjectTargetSelector::updateAction()
QString runConfig;
QIcon targetIcon = style()->standardIcon(QStyle::SP_ComputerIcon);
const int extrawidth = 110; // Size of margins + icon width
// Some fudge numbers to ensure the menu doesnt grow unbounded
int maxLength = fontMetrics().averageCharWidth() * 140;
if (project) {
projectName = project->displayName();
......@@ -585,10 +596,14 @@ void MiniProjectTargetSelector::updateAction()
}
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
buildConfig = bc->displayName();
int minimumWidth = fontMetrics().width(bc->displayName() + tr("Build:")) + extrawidth;
m_widgetStack->setMinimumWidth(qMin(maxLength, qMax(minimumWidth, m_widgetStack->minimumWidth())));
}
if (RunConfiguration *rc = target->activeRunConfiguration()) {
runConfig = rc->displayName();
int minimumWidth = fontMetrics().width(rc->displayName() + tr("Run:")) + extrawidth;
m_widgetStack->setMinimumWidth(qMin(maxLength, qMax(minimumWidth, m_widgetStack->minimumWidth())));
}
targetToolTipText = target->toolTip();
targetIcon = createCenteredIcon(target->icon(), target->overlayIcon());
......
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