Commit ac074618 authored by Dan Pascu's avatar Dan Pascu

Added text eliding using fading colors for labels with long texts

parent cab1483e
......@@ -1298,8 +1298,7 @@ class ContactDelegate(QStyledItemDelegate):
else:
widget = self.contact_oddline_widget
item_size = option.rect.size()
if widget.size() != item_size:
widget.resize(item_size)
widget.setFixedSize(item_size)
widget.init_from_contact(contact)
painter.save()
......
# Copyright (c) 2010 AG Projects. See LICENSE for details.
#
__all__ = ['DurationLabel', 'IconSelector', 'LatencyLabel', 'PacketLossLabel', 'Status', 'StatusLabel', 'StreamInfoLabel']
__all__ = ['DurationLabel', 'IconSelector', 'LatencyLabel', 'PacketLossLabel', 'Status', 'StatusLabel', 'StreamInfoLabel', 'ElidedLabel']
import os
from datetime import timedelta
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QColor, QFileDialog, QFontMetrics, QLabel, QPalette, QPixmap
from PyQt4.QtGui import QBrush, QColor, QFileDialog, QFontMetrics, QLabel, QLinearGradient, QPalette, QPainter, QPen, QPixmap
from blink.resources import ApplicationData, Resources
from blink.widgets.util import QtDynamicProperty
......@@ -183,3 +183,18 @@ class StatusLabel(QLabel):
del _get_value, _set_value
class ElidedLabel(QLabel):
"""A label that elides the text using a fading gradient"""
def paintEvent(self, event):
painter = QPainter(self)
font_metrics = QFontMetrics(self.font())
if font_metrics.width(self.text()) > self.contentsRect().width():
label_width = self.size().width()
gradient = QLinearGradient(0, 0, label_width, 0)
gradient.setColorAt(1-50.0/label_width, self.palette().color(self.foregroundRole()))
gradient.setColorAt(1.0, Qt.transparent)
painter.setPen(QPen(QBrush(gradient), 1.0))
painter.drawText(self.rect(), Qt.TextSingleLine | int(self.alignment()), self.text())
......@@ -117,8 +117,11 @@
<property name="spacing">
<number>0</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<item>
<widget class="QLabel" name="name_label">
<widget class="ElidedLabel" name="name_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -131,7 +134,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="info_label">
<widget class="ElidedLabel" name="info_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -139,7 +142,7 @@
</sizepolicy>
</property>
<property name="text">
<string>URI</string>
<string>Info</string>
</property>
</widget>
</item>
......@@ -147,6 +150,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
<header>blink.widgets.labels</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -68,7 +68,7 @@ border-width: 0;
<number>0</number>
</property>
<item>
<widget class="QLabel" name="name_label">
<widget class="ElidedLabel" name="name_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -220,6 +220,11 @@ border-color: #3278c8;
<extends>QLineEdit</extends>
<header>blink.widgets.lineedit</header>
</customwidget>
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
<header>blink.widgets.labels</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
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