Commit 89e418ef authored by Eike Ziller's avatar Eike Ziller

Projects mode: Adapt kit selector width to kit names

It now grows at least within a certain range

Task-number: QTCREATORBUG-9566
Change-Id: Ie64a0c0c75ca7ac3a2e709bd27ba66a95b870634
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent a2a55368
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
static const int TARGET_HEIGHT = 43; static const int TARGET_HEIGHT = 43;
static const int NAVBUTTON_WIDTH = 27; static const int NAVBUTTON_WIDTH = 27;
static const int KITNAME_MARGINS = 6;
namespace ProjectExplorer { namespace ProjectExplorer {
namespace Internal { namespace Internal {
...@@ -86,7 +87,8 @@ TargetSelector::TargetSelector(QWidget *parent) : ...@@ -86,7 +87,8 @@ TargetSelector::TargetSelector(QWidget *parent) :
m_currentTargetIndex(-1), m_currentTargetIndex(-1),
m_currentHoveredTargetIndex(-1), m_currentHoveredTargetIndex(-1),
m_startIndex(0), m_startIndex(0),
m_menuShown(false) m_menuShown(false),
m_targetWidthNeedsUpdate(true)
{ {
QFont f = font(); QFont f = font();
f.setPixelSize(10); f.setPixelSize(10);
...@@ -129,6 +131,7 @@ void TargetSelector::insertTarget(int index, int subIndex, const QString &name) ...@@ -129,6 +131,7 @@ void TargetSelector::insertTarget(int index, int subIndex, const QString &name)
if (m_currentTargetIndex >= index) if (m_currentTargetIndex >= index)
setCurrentIndex(m_currentTargetIndex + 1); setCurrentIndex(m_currentTargetIndex + 1);
m_targetWidthNeedsUpdate = true;
updateGeometry(); updateGeometry();
update(); update();
} }
...@@ -136,6 +139,8 @@ void TargetSelector::insertTarget(int index, int subIndex, const QString &name) ...@@ -136,6 +139,8 @@ void TargetSelector::insertTarget(int index, int subIndex, const QString &name)
void TargetSelector::renameTarget(int index, const QString &name) void TargetSelector::renameTarget(int index, const QString &name)
{ {
m_targets[index].name = name; m_targets[index].name = name;
m_targetWidthNeedsUpdate = true;
updateGeometry();
update(); update();
} }
...@@ -150,6 +155,7 @@ void TargetSelector::removeTarget(int index) ...@@ -150,6 +155,7 @@ void TargetSelector::removeTarget(int index)
// force a signal since the index has changed // force a signal since the index has changed
emit currentChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex); emit currentChanged(m_currentTargetIndex, m_targets.at(m_currentTargetIndex).currentSubIndex);
} }
m_targetWidthNeedsUpdate = true;
updateGeometry(); updateGeometry();
update(); update();
} }
...@@ -212,10 +218,16 @@ void TargetSelector::setTargetMenu(QMenu *menu) ...@@ -212,10 +218,16 @@ void TargetSelector::setTargetMenu(QMenu *menu)
int TargetSelector::targetWidth() const int TargetSelector::targetWidth() const
{ {
static int width = -1; static int width = -1;
if (width < 0) { if (width < 0 || m_targetWidthNeedsUpdate) {
m_targetWidthNeedsUpdate = false;
QFontMetrics fm = fontMetrics(); QFontMetrics fm = fontMetrics();
width = qMax(fm.width(runButtonString()), fm.width(buildButtonString())); width = 149; // minimum
width = qMax(149, width * 2 + 31); // let it grow for the kit names ...
foreach (const Target &target, m_targets)
width = qMax(width, fm.width(target.name) + KITNAME_MARGINS + 2/*safety measure*/);
width = qMin(width, 299); // ... but not too much
int buttonWidth = qMax(fm.width(runButtonString()), fm.width(buildButtonString()));
width = qMax(width, buttonWidth * 2 + 31); // run & build button strings must be fully visible
} }
return width; return width;
} }
...@@ -416,7 +428,7 @@ void TargetSelector::paintEvent(QPaintEvent *event) ...@@ -416,7 +428,7 @@ void TargetSelector::paintEvent(QPaintEvent *event)
QRect buttonRect(x, 1, targetWidth() , image.height()); QRect buttonRect(x, 1, targetWidth() , image.height());
Utils::StyleHelper::drawCornerImage(image, &p, buttonRect, 16, 0, 16, 0); Utils::StyleHelper::drawCornerImage(image, &p, buttonRect, 16, 0, 16, 0);
const QString nameText = QFontMetrics(font()).elidedText(target.name, Qt::ElideRight, const QString nameText = QFontMetrics(font()).elidedText(target.name, Qt::ElideRight,
targetWidth() - 6); targetWidth() - KITNAME_MARGINS);
p.drawText(x + (targetWidth()- fm.width(nameText))/2 + 1, 7 + fm.ascent(), p.drawText(x + (targetWidth()- fm.width(nameText))/2 + 1, 7 + fm.ascent(),
nameText); nameText);
......
...@@ -116,6 +116,7 @@ private: ...@@ -116,6 +116,7 @@ private:
int m_currentHoveredTargetIndex; int m_currentHoveredTargetIndex;
int m_startIndex; int m_startIndex;
bool m_menuShown; bool m_menuShown;
mutable bool m_targetWidthNeedsUpdate;
}; };
} // namespace Internal } // namespace Internal
......
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