Calculate max short id width differently

Fixes #343.
This commit is contained in:
Jason Haslam 2019-12-16 12:03:32 -07:00
parent 8dbc57207c
commit 374b4fa07a
4 changed files with 95 additions and 71 deletions

View File

@ -656,99 +656,99 @@
<context>
<name>CommitList</name>
<message>
<location filename="../src/ui/CommitList.cpp" line="1414"/>
<location filename="../src/ui/CommitList.cpp" line="1438"/>
<source>Remove Untracked Files</source>
<translation>Ungetrackte Dateien entfernen</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1431"/>
<location filename="../src/ui/CommitList.cpp" line="1455"/>
<source>Apply</source>
<translation>Anwenden</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1435"/>
<location filename="../src/ui/CommitList.cpp" line="1459"/>
<source>Pop</source>
<translation>Poppen</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1439"/>
<location filename="../src/ui/CommitList.cpp" line="1463"/>
<source>Drop</source>
<translation>Droppen</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1453"/>
<location filename="../src/ui/CommitList.cpp" line="1477"/>
<source>Unstar</source>
<translation>Ent-Favorisieren</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1453"/>
<location filename="../src/ui/CommitList.cpp" line="1477"/>
<source>Star</source>
<translation>Favorisieren</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1462"/>
<location filename="../src/ui/CommitList.cpp" line="1486"/>
<source>Add Tag...</source>
<translation>Tag hinzufügen...</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1466"/>
<location filename="../src/ui/CommitList.cpp" line="1490"/>
<source>New Branch...</source>
<translation>Neuer Branch...</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1472"/>
<location filename="../src/ui/CommitList.cpp" line="1496"/>
<source>Merge...</source>
<translation>Mergen...</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1487"/>
<location filename="../src/ui/CommitList.cpp" line="1511"/>
<source>Rebase...</source>
<translation>Rebasen...</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1502"/>
<location filename="../src/ui/CommitList.cpp" line="1526"/>
<source>Revert</source>
<translation>Reverten</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1506"/>
<location filename="../src/ui/CommitList.cpp" line="1530"/>
<source>Cherry-pick</source>
<translation>Cherry-Picken</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1515"/>
<location filename="../src/ui/CommitList.cpp" line="1525"/>
<location filename="../src/ui/CommitList.cpp" line="1545"/>
<location filename="../src/ui/CommitList.cpp" line="1539"/>
<location filename="../src/ui/CommitList.cpp" line="1549"/>
<location filename="../src/ui/CommitList.cpp" line="1569"/>
<source>Checkout %1</source>
<translation>%1 auschecken</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1536"/>
<location filename="../src/ui/CommitList.cpp" line="1560"/>
<source>Local branch is already checked out</source>
<translation>Ein lokaler Branch ist bereits ausgecheckt</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1539"/>
<location filename="../src/ui/CommitList.cpp" line="1563"/>
<source>This is a bare repository</source>
<translation>Dies ist ein Bare-Repository</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1556"/>
<location filename="../src/ui/CommitList.cpp" line="1580"/>
<source>Reset</source>
<translation>Zurücksetzen</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1557"/>
<location filename="../src/ui/CommitList.cpp" line="1581"/>
<source>Soft</source>
<translation>Soft</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1558"/>
<location filename="../src/ui/CommitList.cpp" line="1582"/>
<source>Mixed</source>
<translation>Mixed</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1559"/>
<location filename="../src/ui/CommitList.cpp" line="1583"/>
<source>Hard</source>
<translation>Hard</translation>
</message>
@ -756,12 +756,12 @@
<context>
<name>CommitModel</name>
<message>
<location filename="../src/ui/CommitList.cpp" line="346"/>
<location filename="../src/ui/CommitList.cpp" line="351"/>
<source>Uncommitted changes</source>
<translation>Uncommittete Änderungen</translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="347"/>
<location filename="../src/ui/CommitList.cpp" line="352"/>
<source>Checking for uncommitted changes</source>
<translation>Prüfe auf uncommittete Änderungen</translation>
</message>

View File

@ -656,99 +656,99 @@
<context>
<name>CommitList</name>
<message>
<location filename="../src/ui/CommitList.cpp" line="1414"/>
<location filename="../src/ui/CommitList.cpp" line="1438"/>
<source>Remove Untracked Files</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1431"/>
<location filename="../src/ui/CommitList.cpp" line="1455"/>
<source>Apply</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1435"/>
<location filename="../src/ui/CommitList.cpp" line="1459"/>
<source>Pop</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1439"/>
<location filename="../src/ui/CommitList.cpp" line="1463"/>
<source>Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1453"/>
<location filename="../src/ui/CommitList.cpp" line="1477"/>
<source>Unstar</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1453"/>
<location filename="../src/ui/CommitList.cpp" line="1477"/>
<source>Star</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1462"/>
<location filename="../src/ui/CommitList.cpp" line="1486"/>
<source>Add Tag...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1466"/>
<location filename="../src/ui/CommitList.cpp" line="1490"/>
<source>New Branch...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1472"/>
<location filename="../src/ui/CommitList.cpp" line="1496"/>
<source>Merge...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1487"/>
<location filename="../src/ui/CommitList.cpp" line="1511"/>
<source>Rebase...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1502"/>
<location filename="../src/ui/CommitList.cpp" line="1526"/>
<source>Revert</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1506"/>
<location filename="../src/ui/CommitList.cpp" line="1530"/>
<source>Cherry-pick</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1515"/>
<location filename="../src/ui/CommitList.cpp" line="1525"/>
<location filename="../src/ui/CommitList.cpp" line="1545"/>
<location filename="../src/ui/CommitList.cpp" line="1539"/>
<location filename="../src/ui/CommitList.cpp" line="1549"/>
<location filename="../src/ui/CommitList.cpp" line="1569"/>
<source>Checkout %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1536"/>
<location filename="../src/ui/CommitList.cpp" line="1560"/>
<source>Local branch is already checked out</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1539"/>
<location filename="../src/ui/CommitList.cpp" line="1563"/>
<source>This is a bare repository</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1556"/>
<location filename="../src/ui/CommitList.cpp" line="1580"/>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1557"/>
<location filename="../src/ui/CommitList.cpp" line="1581"/>
<source>Soft</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1558"/>
<location filename="../src/ui/CommitList.cpp" line="1582"/>
<source>Mixed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1559"/>
<location filename="../src/ui/CommitList.cpp" line="1583"/>
<source>Hard</source>
<translation type="unfinished"></translation>
</message>
@ -756,12 +756,12 @@
<context>
<name>CommitModel</name>
<message>
<location filename="../src/ui/CommitList.cpp" line="346"/>
<location filename="../src/ui/CommitList.cpp" line="351"/>
<source>Uncommitted changes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="347"/>
<location filename="../src/ui/CommitList.cpp" line="352"/>
<source>Checking for uncommitted changes</source>
<translation type="unfinished"></translation>
</message>

View File

@ -656,99 +656,99 @@
<context>
<name>CommitList</name>
<message>
<location filename="../src/ui/CommitList.cpp" line="1414"/>
<location filename="../src/ui/CommitList.cpp" line="1438"/>
<source>Remove Untracked Files</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1431"/>
<location filename="../src/ui/CommitList.cpp" line="1455"/>
<source>Apply</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1435"/>
<location filename="../src/ui/CommitList.cpp" line="1459"/>
<source>Pop</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1439"/>
<location filename="../src/ui/CommitList.cpp" line="1463"/>
<source>Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1453"/>
<location filename="../src/ui/CommitList.cpp" line="1477"/>
<source>Unstar</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1453"/>
<location filename="../src/ui/CommitList.cpp" line="1477"/>
<source>Star</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1462"/>
<location filename="../src/ui/CommitList.cpp" line="1486"/>
<source>Add Tag...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1466"/>
<location filename="../src/ui/CommitList.cpp" line="1490"/>
<source>New Branch...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1472"/>
<location filename="../src/ui/CommitList.cpp" line="1496"/>
<source>Merge...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1487"/>
<location filename="../src/ui/CommitList.cpp" line="1511"/>
<source>Rebase...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1502"/>
<location filename="../src/ui/CommitList.cpp" line="1526"/>
<source>Revert</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1506"/>
<location filename="../src/ui/CommitList.cpp" line="1530"/>
<source>Cherry-pick</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1515"/>
<location filename="../src/ui/CommitList.cpp" line="1525"/>
<location filename="../src/ui/CommitList.cpp" line="1545"/>
<location filename="../src/ui/CommitList.cpp" line="1539"/>
<location filename="../src/ui/CommitList.cpp" line="1549"/>
<location filename="../src/ui/CommitList.cpp" line="1569"/>
<source>Checkout %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1536"/>
<location filename="../src/ui/CommitList.cpp" line="1560"/>
<source>Local branch is already checked out</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1539"/>
<location filename="../src/ui/CommitList.cpp" line="1563"/>
<source>This is a bare repository</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1556"/>
<location filename="../src/ui/CommitList.cpp" line="1580"/>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1557"/>
<location filename="../src/ui/CommitList.cpp" line="1581"/>
<source>Soft</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1558"/>
<location filename="../src/ui/CommitList.cpp" line="1582"/>
<source>Mixed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="1559"/>
<location filename="../src/ui/CommitList.cpp" line="1583"/>
<source>Hard</source>
<translation type="unfinished"></translation>
</message>
@ -756,12 +756,12 @@
<context>
<name>CommitModel</name>
<message>
<location filename="../src/ui/CommitList.cpp" line="346"/>
<location filename="../src/ui/CommitList.cpp" line="351"/>
<source>Uncommitted changes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ui/CommitList.cpp" line="347"/>
<location filename="../src/ui/CommitList.cpp" line="352"/>
<source>Checking for uncommitted changes</source>
<translation type="unfinished"></translation>
</message>

View File

@ -40,8 +40,13 @@ namespace {
// FIXME: Factor out into theme?
const QColor kTaintedColor = Qt::gray;
const QString kPathspecFmt = "pathspec:%1";
// Use fixed short id size in compact mode.
// FIXME: Use 'core.abbrev' config instead?
const int kShortIdSize = 7;
enum Role
{
DiffRole = Qt::UserRole,
@ -830,8 +835,8 @@ public:
rect.setWidth(rect.width() - star.width());
// Draw commit id.
QString id = commit.id().toString().left(7);
int idWidth = fm.boundingRect(QString(id.size(), '0')).width();
QString id = commit.id().toString().left(kShortIdSize);
int idWidth = maxShortIdWidth(fm);
QRect commitRect = rect;
commitRect.setX(commitRect.x() + commitRect.width() - idWidth);
@ -1090,8 +1095,27 @@ private:
}
}
int maxShortIdWidth(const QFontMetrics &fm) const
{
if (mMaxShortIdWidth < 0) {
for (char ch = 'a'; ch <= 'f'; ++ch) {
int width = fm.boundingRect(QString(kShortIdSize, ch)).width();
mMaxShortIdWidth = qMax(mMaxShortIdWidth, width);
}
for (char ch = '0'; ch <= '9'; ++ch) {
int width = fm.boundingRect(QString(kShortIdSize, ch)).width();
mMaxShortIdWidth = qMax(mMaxShortIdWidth, width);
}
}
return mMaxShortIdWidth;
}
git::Repository mRepo;
QMap<git::Id,QList<Badge::Label>> mRefs;
mutable int mMaxShortIdWidth = -1;
};
class SelectionModel : public QItemSelectionModel