Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9.2, 1.9.3, and 2.0

chunks: hide filename label until it can be elided

Elided text is not a native feature of QLabel, so we'll need to develop a class
for this and move it to qtlib.

Changeset 718fd21f08fc

Parent 703ae086e86e

by Steve Borho

Changes to one file · Browse files at 718fd21f08fc Showing diff from parent 703ae086e86e Diff from another changeset...

 
371
372
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
375
376
 
396
397
398
 
399
400
401
 
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
 
415
416
417
418
419
420
421
@@ -371,6 +371,25 @@
  ctx = self.repo.changectx(ctx.node())   self.setContext(ctx)   +# DO NOT USE. Sadly, this does not work. +class ElideLabel(QLabel): + def __init__(self, text='', parent=None): + QLabel.__init__(self, text, parent) + + def sizeHint(self): + return super(ElideLabel, self).sizeHint() + + def paintEvent(self, event): + p = QPainter() + fm = QFontMetrics(self.font()) + if fm.width(self.text()): # > self.contentsRect().width(): + elided = fm.elidedText(self.text(), Qt.ElideLeft, + self.rect().width(), 0) + p.drawText(self.rect(), Qt.AlignTop | Qt.AlignRight | + Qt.TextSingleLine, elided) + else: + super(ElideLabel, self).paintEvent(event) +  class DiffBrowser(QFrame):   """diff browser"""   @@ -396,6 +415,7 @@
  hbox.setSpacing(2)   self.layout().addLayout(hbox)   self.filenamelabel = w = QLabel() + self.filenamelabel.hide()   hbox.addWidget(w)   w.setWordWrap(True)   f = w.textInteractionFlags()