35 @param event reference to the paint event (QPaintEvent) |
37 @param event reference to the paint event (QPaintEvent) |
36 """ |
38 """ |
37 fm = self.fontMetrics() |
39 fm = self.fontMetrics() |
38 if fm.width(self.__text) > self.contentsRect().width(): |
40 if fm.width(self.__text) > self.contentsRect().width(): |
39 self.__elided = fm.elidedText(self.text(), Qt.ElideMiddle, self.width()) |
41 self.__elided = fm.elidedText(self.text(), Qt.ElideMiddle, self.width()) |
40 super().setText(self.__elided) |
42 super(E5SqueezeLabel, self).setText(self.__elided) |
41 else: |
43 else: |
42 super().setText(self.__text) |
44 super(E5SqueezeLabel, self).setText(self.__text) |
43 super().paintEvent(event) |
45 super(E5SqueezeLabel, self).paintEvent(event) |
44 |
46 |
45 def setText(self, txt): |
47 def setText(self, txt): |
46 """ |
48 """ |
47 Public method to set the label's text. |
49 Public method to set the label's text. |
48 |
50 |
49 @param txt the text to be shown (string) |
51 @param txt the text to be shown (string) |
50 """ |
52 """ |
51 self.__text = txt |
53 self.__text = txt |
52 super().setText(self.__text) |
54 super(E5SqueezeLabel, self).setText(self.__text) |
53 |
55 |
54 |
56 |
55 class E5SqueezeLabelPath(QLabel): |
57 class E5SqueezeLabelPath(QLabel): |
56 """ |
58 """ |
57 Class implementing a label showing a file path compacted to fit it's size. |
59 Class implementing a label showing a file path compacted to fit it's size. |
72 Public method to set the surrounding of the path string. |
74 Public method to set the surrounding of the path string. |
73 |
75 |
74 @param surrounding the a string containg placeholders for the path (string) |
76 @param surrounding the a string containg placeholders for the path (string) |
75 """ |
77 """ |
76 self.__surrounding = surrounding |
78 self.__surrounding = surrounding |
77 super().setText(self.__surrounding.format(self.__path)) |
79 super(E5SqueezeLabelPath, self).setText(self.__surrounding.format(self.__path)) |
78 |
80 |
79 def setPath(self, path): |
81 def setPath(self, path): |
80 """ |
82 """ |
81 Public method to set the path of the label. |
83 Public method to set the path of the label. |
82 |
84 |
83 @param path path to be shown (string) |
85 @param path path to be shown (string) |
84 """ |
86 """ |
85 self.__path = path |
87 self.__path = path |
86 super().setText(self.__surrounding.format(self.__path)) |
88 super(E5SqueezeLabelPath, self).setText(self.__surrounding.format(self.__path)) |
87 |
89 |
88 def setTextPath(self, surrounding, path): |
90 def setTextPath(self, surrounding, path): |
89 """ |
91 """ |
90 Public method to set the surrounding and the path of the label. |
92 Public method to set the surrounding and the path of the label. |
91 |
93 |
92 @param surrounding the a string containg placeholders for the path (string) |
94 @param surrounding the a string containg placeholders for the path (string) |
93 @param path path to be shown (string) |
95 @param path path to be shown (string) |
94 """ |
96 """ |
95 self.__surrounding = surrounding |
97 self.__surrounding = surrounding |
96 self.__path = path |
98 self.__path = path |
97 super().setText(self.__surrounding.format(self.__path)) |
99 super(E5SqueezeLabelPath, self).setText(self.__surrounding.format(self.__path)) |
98 |
100 |
99 def paintEvent(self, event): |
101 def paintEvent(self, event): |
100 """ |
102 """ |
101 Protected method called when some painting is required. |
103 Protected method called when some painting is required. |
102 |
104 |
103 @param event reference to the paint event (QPaintEvent) |
105 @param event reference to the paint event (QPaintEvent) |
104 """ |
106 """ |
105 fm = self.fontMetrics() |
107 fm = self.fontMetrics() |
106 if fm.width(self.__surrounding.format(self.__path)) > self.contentsRect().width(): |
108 if fm.width(self.__surrounding.format(self.__path)) > self.contentsRect().width(): |
107 super().setText( |
109 super(E5SqueezeLabelPath, self).setText( |
108 self.__surrounding.format(compactPath(self.__path, |
110 self.__surrounding.format(compactPath(self.__path, |
109 self.contentsRect().width(), |
111 self.contentsRect().width(), |
110 self.length)) |
112 self.length)) |
111 ) |
113 ) |
112 else: |
114 else: |
113 super().setText(self.__surrounding.format(self.__path)) |
115 super(E5SqueezeLabelPath, self).setText(self.__surrounding.format(self.__path)) |
114 super().paintEvent(event) |
116 super(E5SqueezeLabelPath, self).paintEvent(event) |
115 |
117 |
116 def length(self, txt): |
118 def length(self, txt): |
117 """ |
119 """ |
118 Public method to return the length of a text in pixels. |
120 Public method to return the length of a text in pixels. |
119 |
121 |