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): ...@@ -1298,8 +1298,7 @@ class ContactDelegate(QStyledItemDelegate):
else: else:
widget = self.contact_oddline_widget widget = self.contact_oddline_widget
item_size = option.rect.size() item_size = option.rect.size()
if widget.size() != item_size: widget.setFixedSize(item_size)
widget.resize(item_size)
widget.init_from_contact(contact) widget.init_from_contact(contact)
painter.save() painter.save()
......
# Copyright (c) 2010 AG Projects. See LICENSE for details. # 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 import os
from datetime import timedelta from datetime import timedelta
from PyQt4.QtCore import Qt 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.resources import ApplicationData, Resources
from blink.widgets.util import QtDynamicProperty from blink.widgets.util import QtDynamicProperty
...@@ -183,3 +183,18 @@ class StatusLabel(QLabel): ...@@ -183,3 +183,18 @@ class StatusLabel(QLabel):
del _get_value, _set_value 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 @@ ...@@ -117,8 +117,11 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin">
<number>8</number>
</property>
<item> <item>
<widget class="QLabel" name="name_label"> <widget class="ElidedLabel" name="name_label">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -131,7 +134,7 @@ ...@@ -131,7 +134,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="info_label"> <widget class="ElidedLabel" name="info_label">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -139,7 +142,7 @@ ...@@ -139,7 +142,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>URI</string> <string>Info</string>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -147,6 +150,13 @@ ...@@ -147,6 +150,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
<header>blink.widgets.labels</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>
...@@ -68,7 +68,7 @@ border-width: 0; ...@@ -68,7 +68,7 @@ border-width: 0;
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="name_label"> <widget class="ElidedLabel" name="name_label">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -220,6 +220,11 @@ border-color: #3278c8; ...@@ -220,6 +220,11 @@ border-color: #3278c8;
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>blink.widgets.lineedit</header> <header>blink.widgets.lineedit</header>
</customwidget> </customwidget>
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
<header>blink.widgets.labels</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <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