def set_from_file(self, filename, blocked=False): self.filename = filename self.blocked = blocked if filename and not os.path.exists(filename): if self._size.width() > 32: # use big fallback image self.filename = gui.theme.image_theme.user_def_imagetool else: self.filename = gui.theme.image_theme.user pic_handler = PictureHandler.PictureHandler(self.filename) if pic_handler.can_handle(): pixmap = QtGui.QPixmap(self.filename) if pixmap.isNull(): pixmap = QtGui.QPixmap(gui.theme.image_theme.user) pixmap = Utils.pixmap_rounder(pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) if self.crossfade: self._fader.add_pixmap(pixmap) else: self.setPixmap(pixmap) else: self._movie = QtGui.QMovie(self.filename) self._movie.setScaledSize(self._size) if self.crossfade: self._fader.add_pixmap(self._movie) else: self.setMovie(self._movie) if self.blocked: #FIXME: implement pass self._last = self.filename
def set_from_file(self, filename, blocked=False): self.filename = filename self.blocked = blocked if filename and not os.path.exists(filename): if self._size.width() > 32: # use big fallback image self.filename = gui.theme.image_theme.user_def_imagetool else: self.filename = gui.theme.image_theme.user pic_handler = PictureHandler.PictureHandler(self.filename) if pic_handler.can_handle(): pixmap = QtGui.QPixmap(self.filename) if pixmap.isNull(): pixmap = QtGui.QPixmap(gui.theme.image_theme.user) pixmap = Utils.pixmap_rounder( pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) if self.crossfade: self._fader.add_pixmap(pixmap) else: self.setPixmap(pixmap) else: self._movie = QtGui.QMovie(self.filename) self._movie.setScaledSize(self._size) if self.crossfade: self._fader.add_pixmap(self._movie) else: self.setMovie(self._movie) if self.blocked: #FIXME: implement pass self._last = self.filename
def _rescale_picture(self, picture, filename): if isinstance(picture, QtGui.QMovie): return picture.setScaledSize(self._size) else: pixmap = QtGui.QPixmap(filename) if not pixmap.isNull(): pixmap = Utils.pixmap_rounder(pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) return pixmap
def _rescale_picture(self, picture, filename): if isinstance(picture, QtGui.QMovie): return picture.setScaledSize(self._size) else: pixmap = QtGui.QPixmap(filename) if not pixmap.isNull(): pixmap = Utils.pixmap_rounder( pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) return pixmap
def set_display_pic_from_file(self, path): ''' sets the display pic from the path''' pic_handler = PictureHandler.PictureHandler(path) if pic_handler.can_handle(): pixmap = QtGui.QPixmap(path) if pixmap.isNull(): pixmap = QtGui.QPixmap(self._default_pic) pixmap = Utils.pixmap_rounder(pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) self._fader.add_pixmap(pixmap) else: self._movie = QtGui.QMovie(path) self._fader.add_pixmap(self._movie) self._last = path
def drawWidget(self, painter): painter.save() painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) old_pixmap, old_opacity, old_filename = self._back new_pixmap, new_opacity, new_filename = self._front if isinstance(self._back[0], QtGui.QMovie): old_pixmap = old_pixmap.currentPixmap() if isinstance(self._front[0], QtGui.QMovie): new_pixmap = new_pixmap.currentPixmap() new_pixmap = Utils.pixmap_rounder( new_pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) if not self.crossfade: painter.drawPixmap(self._rect, new_pixmap, self._rect) else: painter.fillRect(self._rect, Qt.transparent) painter.setCompositionMode(QtGui.QPainter.CompositionMode_Source) #FIXME: old pixmap fading isn't working correctly # painter.setOpacity(old_opacity) painter.setOpacity(0) painter.drawPixmap(self._rect, old_pixmap, self._rect) painter.setCompositionMode( QtGui.QPainter.CompositionMode_SourceOver) painter.setOpacity(new_opacity) painter.drawPixmap(self._rect, new_pixmap, self._rect) if self.blocked: origin = QtCore.QPointF(0.0, 0.0) source = QtCore.QRectF(origin, QtCore.QSizeF(self.blocked_pic.size())) x_emblem_offset = self._size.width() - self.blocked_pic.size( ).width() y_emblem_offset = self._size.height() - self.blocked_pic.size( ).height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF(origin + xy_emblem_offset, QtCore.QSizeF(self.blocked_pic.size())) painter.setCompositionMode( QtGui.QPainter.CompositionMode_SourceOver) painter.drawPixmap(target, self.blocked_pic, source) painter.restore()
def set_from_file(self, filename, blocked=False): self.blocked = blocked pixmap = self._fallback if filename is not None and os.path.exists(filename): self.filename = filename pic_handler = PictureHandler.PictureHandler(self.filename) if pic_handler.can_handle(): pixmap = QtGui.QPixmap(self.filename) if not pixmap.isNull(): pixmap = Utils.pixmap_rounder(pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) else: self._movie = QtGui.QMovie(self.filename) self._movie.setScaledSize(self._size) self._movie.start() pixmap = self._movie else: filename = self._get_fallback_image() self.add_pixmap(pixmap, filename)
def drawWidget(self, painter): painter.save() painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) old_pixmap, old_opacity, old_filename = self._back new_pixmap, new_opacity, new_filename = self._front if isinstance(self._back[0], QtGui.QMovie): old_pixmap = old_pixmap.currentPixmap() if isinstance(self._front[0], QtGui.QMovie): new_pixmap = new_pixmap.currentPixmap() new_pixmap = Utils.pixmap_rounder(new_pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) if not self.crossfade: painter.drawPixmap(self._rect, new_pixmap, self._rect) else: painter.fillRect(self._rect, Qt.transparent) painter.setCompositionMode(QtGui.QPainter.CompositionMode_Source) #FIXME: old pixmap fading isn't working correctly # painter.setOpacity(old_opacity) painter.setOpacity(0) painter.drawPixmap(self._rect, old_pixmap, self._rect) painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver) painter.setOpacity(new_opacity) painter.drawPixmap(self._rect, new_pixmap, self._rect) if self.blocked: origin = QtCore.QPointF(0.0, 0.0) source = QtCore.QRectF(origin, QtCore.QSizeF(self.blocked_pic.size()) ) x_emblem_offset = self._size.width() - self.blocked_pic.size().width() y_emblem_offset = self._size.height() - self.blocked_pic.size().height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF(origin + xy_emblem_offset, QtCore.QSizeF(self.blocked_pic.size())) painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver) painter.drawPixmap(target, self.blocked_pic, source) painter.restore()
def set_from_file(self, filename, blocked=False): self.blocked = blocked pixmap = self._fallback if filename is not None and os.path.exists(filename): self.filename = filename pic_handler = PictureHandler.PictureHandler(self.filename) if pic_handler.can_handle(): pixmap = QtGui.QPixmap(self.filename) if not pixmap.isNull(): pixmap = Utils.pixmap_rounder( pixmap.scaled(self._size, transformMode=Qt.SmoothTransformation)) else: self._movie = QtGui.QMovie(self.filename) self._movie.setScaledSize(self._size) self._movie.start() pixmap = self._movie else: filename = self._get_fallback_image() self.add_pixmap(pixmap, filename)
def paint(self, painter, option, index): '''Paints the contact''' # pylint: disable=C0103 model = index.model() painter.save() painter.translate(0, 0) # -> Configure the painter painter.setRenderHint(QtGui.QPainter.Antialiasing) # especially useful for scaled smileys. painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) painter.setClipRect(option.rect) painter.setClipping(True) # -> Draw the skeleton of a ItemView widget: highlighting, selection... QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_ItemViewItem, option, painter, self.parent()) status = model.data(index, Role.StatusRole).toPyObject() text_doc = QtGui.QTextDocument() origin = QtCore.QPointF(0.0, 0.0) if not index.parent().isValid(): # -> Start drawing the text_doc: text_list = self._build_display_role(index, True) painter.translate( QtCore.QPointF(option.rect.topLeft()) ) # create the text_doc self._put_display_role(text_doc, text_list) # draw the text_doc text_doc.drawContents(painter) else: top_left_point = QtCore.QPointF(option.rect.topLeft()) # a little additional margin # TODO: try to do this for the highlighting too top_left_point.setX( top_left_point.x() + 5 ) # -> Start drawing the decoration: # calc y_pic_margin = abs((option.rect.height() - self._picture_size)) / 2 x_pic_margin = self._MIN_PICTURE_MARGIN xy_pic_margin = QtCore.QPointF(x_pic_margin, y_pic_margin) # create the picture picture_path = model.data(index, Role.DecorationRole).toString() picture = QtGui.QPixmap(picture_path) if picture.isNull(): picture = QtGui.QPixmap(gui.theme.image_theme.user) else: picture = Utils.pixmap_rounder(picture) #FIXME: when we scale to big sizes status icon is lost by some reason #scale picture scaledpicture = picture.scaled(self._pic_size, transformMode=Qt.SmoothTransformation) # calculate the target position source = QtCore.QRectF( origin, QtCore.QSizeF(scaledpicture.size())) target = QtCore.QRectF( top_left_point + xy_pic_margin, self._pic_sizef) # draw the picture painter.drawPixmap(target, scaledpicture, source) # -> start drawing the 'blocked' emblem if model.data(index, Role.BlockedRole).toPyObject(): source = QtCore.QRectF( origin, QtCore.QSizeF(self.blocked_pic.size()) ) x_emblem_offset = self._picture_size - self.blocked_pic.size().width() y_emblem_offset = self._picture_size - self.blocked_pic.size().height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF( top_left_point + xy_pic_margin + xy_emblem_offset, QtCore.QSizeF(self.blocked_pic.size())) painter.drawPixmap(target, self.blocked_pic, source) # -> set-up status picture for calculations picture_path = gui.theme.image_theme.status_icons[ model.data(index, Role.StatusRole).toPyObject()] picture_status = QtGui.QPixmap(picture_path) # -> Start setting up the text_doc: text_list = self._build_display_role(index) # set the text into text_doc self._put_display_role(text_doc, text_list) # calculate the vertical offset, to center the text_doc vertically y_text_offset = \ abs(option.rect.height() - text_doc.size().height()) / 2 x_text_offset = 2 * x_pic_margin + self._picture_size xy_text_offset = QtCore.QPointF(x_text_offset, y_text_offset) # move the pointer to the text_doc zone: painter.translate(top_left_point + xy_text_offset) #calculate max text width = treeview width - status image width max_text_width = option.rect.width() - 3 * picture_status.size().width() - 2 * x_pic_margin #text width is the min between text_size and max_text_size x_size = min(max_text_width, text_doc.size().width()) #calculate rect size target = QtCore.QRectF( origin, QtCore.QSizeF(x_size, text_doc.size().height()) ) # draw the text_doc text_doc.drawContents(painter, target) # -> start drawing the status emblem source = QtCore.QRectF( origin, QtCore.QSizeF(picture_status.size()) ) x_emblem_offset = max_text_width y_emblem_offset = abs((option.rect.height() - picture_status.size().height())) / 2 xy_emblem_offset = QtCore.QPointF(max_text_width, y_emblem_offset) target = QtCore.QRectF( xy_emblem_offset, QtCore.QSizeF(picture_status.size()) ) painter.drawPixmap(target, picture_status, source) # -> It's done! painter.restore()
def paint(self, painter, option, index): '''Paints the contact''' # pylint: disable=C0103 model = index.model() painter.save() painter.translate(0, 0) # -> Configure the painter painter.setRenderHint(QtGui.QPainter.Antialiasing) # especially useful for scaled smileys. painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) painter.setClipRect(option.rect) painter.setClipping(True) # -> Draw the skeleton of a ItemView widget: highlighting, selection... QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_ItemViewItem, option, painter, self.parent()) status = model.data(index, Role.StatusRole).toPyObject() text_doc = QtGui.QTextDocument() if not index.parent().isValid(): # -> Start drawing the text_doc: text = self._build_display_role(index, True) painter.translate( QtCore.QPointF(option.rect.topLeft()) ) # create the text_doc text_doc.setHtml(text) # draw the text_doc text_doc.drawContents(painter) else: top_left_point = QtCore.QPointF(option.rect.topLeft()) # a little additional margin # TODO: try to do this for the highlighting too top_left_point.setX( top_left_point.x() + 5 ) # -> Start drawing the decoration: # calc y_pic_margin = abs((option.rect.height() - self._PICTURE_SIZE)) / 2 x_pic_margin = self._MIN_PICTURE_MARGIN xy_pic_margin = QtCore.QPointF(x_pic_margin, y_pic_margin) # create the picture picture_path = model.data(index, Role.DecorationRole).toString() picture = QtGui.QPixmap(picture_path) if picture.isNull(): picture = QtGui.QPixmap(gui.theme.image_theme.user) else: picture = Utils.pixmap_rounder(picture) # calculate the target position source = QtCore.QRectF( QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(picture.size()) ) target = QtCore.QRectF( top_left_point + xy_pic_margin, self._pic_size ) # draw the picture painter.drawPixmap(target, picture, source) # -> start drawing the status emblem picture_path = gui.theme.image_theme.status_icons[ model.data(index, Role.StatusRole).toPyObject()] picture = QtGui.QPixmap(picture_path) source = QtCore.QRectF( QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(picture.size()) ) x_emblem_offset = self._PICTURE_SIZE - picture.size().width() y_emblem_offset = self._PICTURE_SIZE - picture.size().height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF( top_left_point + xy_pic_margin + xy_emblem_offset, QtCore.QSizeF(picture.size()) ) painter.drawPixmap(target, picture, source) # -> start drawing the 'blocked' emblem if model.data(index, Role.BlockedRole).toPyObject(): picture_path = gui.theme.image_theme.blocked_overlay picture = QtGui.QPixmap(picture_path) source = QtCore.QRectF( QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(picture.size()) ) x_emblem_offset = 0 y_emblem_offset = self._PICTURE_SIZE - picture.size().height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF( top_left_point + xy_pic_margin + xy_emblem_offset, QtCore.QSizeF(picture.size())) painter.drawPixmap(target, picture, source) # -> Start setting up the text_doc: #text = _build_display_role(index) text = self._build_display_role(index) # set the text into text_doc text_doc.setHtml(text) # calculate the vertical offset, to center the text_doc vertically y_text_offset = \ abs(option.rect.height() - text_doc.size().height()) / 2 x_text_offset = 2 * x_pic_margin + self._PICTURE_SIZE xy_text_offset = QtCore.QPointF(x_text_offset, y_text_offset) # move the pointer to the text_doc zone: painter.translate(top_left_point + xy_text_offset) # draw the text_doc text_doc.drawContents(painter) # -> It's done! painter.restore()
def paint(self, painter, option, index): '''Paints the contact''' # pylint: disable=C0103 model = index.model() painter.save() painter.translate(0, 0) # -> Configure the painter painter.setRenderHint(QtGui.QPainter.Antialiasing) # especially useful for scaled smileys. painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) painter.setClipRect(option.rect) painter.setClipping(True) # -> Draw the skeleton of a ItemView widget: highlighting, selection... QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_ItemViewItem, option, painter, self.parent()) status = model.data(index, Role.StatusRole).toPyObject() text_doc = QtGui.QTextDocument() if not index.parent().isValid(): # -> Start drawing the text_doc: text = self._build_display_role(index, True) painter.translate(QtCore.QPointF(option.rect.topLeft())) # create the text_doc text_doc.setHtml(text) # draw the text_doc text_doc.drawContents(painter) else: top_left_point = QtCore.QPointF(option.rect.topLeft()) # a little additional margin # TODO: try to do this for the highlighting too top_left_point.setX(top_left_point.x() + 5) # -> Start drawing the decoration: # calc y_pic_margin = abs((option.rect.height() - self._PICTURE_SIZE)) / 2 x_pic_margin = self._MIN_PICTURE_MARGIN xy_pic_margin = QtCore.QPointF(x_pic_margin, y_pic_margin) # create the picture picture_path = model.data(index, Role.DecorationRole).toString() picture = QtGui.QPixmap(picture_path) if picture.isNull(): picture = QtGui.QPixmap(gui.theme.image_theme.user) else: picture = Utils.pixmap_rounder(picture) # calculate the target position source = QtCore.QRectF(QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(picture.size())) target = QtCore.QRectF(top_left_point + xy_pic_margin, self._pic_size) # draw the picture painter.drawPixmap(target, picture, source) # -> start drawing the status emblem picture_path = gui.theme.image_theme.status_icons[model.data( index, Role.StatusRole).toPyObject()] picture = QtGui.QPixmap(picture_path) source = QtCore.QRectF(QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(picture.size())) x_emblem_offset = self._PICTURE_SIZE - picture.size().width() y_emblem_offset = self._PICTURE_SIZE - picture.size().height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF( top_left_point + xy_pic_margin + xy_emblem_offset, QtCore.QSizeF(picture.size())) painter.drawPixmap(target, picture, source) # -> start drawing the 'blocked' emblem if model.data(index, Role.BlockedRole).toPyObject(): picture_path = gui.theme.image_theme.blocked_overlay picture = QtGui.QPixmap(picture_path) source = QtCore.QRectF(QtCore.QPointF(0.0, 0.0), QtCore.QSizeF(picture.size())) x_emblem_offset = 0 y_emblem_offset = self._PICTURE_SIZE - picture.size().height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF( top_left_point + xy_pic_margin + xy_emblem_offset, QtCore.QSizeF(picture.size())) painter.drawPixmap(target, picture, source) # -> Start setting up the text_doc: #text = _build_display_role(index) text = self._build_display_role(index) # set the text into text_doc text_doc.setHtml(text) # calculate the vertical offset, to center the text_doc vertically y_text_offset = \ abs(option.rect.height() - text_doc.size().height()) / 2 x_text_offset = 2 * x_pic_margin + self._PICTURE_SIZE xy_text_offset = QtCore.QPointF(x_text_offset, y_text_offset) # move the pointer to the text_doc zone: painter.translate(top_left_point + xy_text_offset) # draw the text_doc text_doc.drawContents(painter) # -> It's done! painter.restore()
def paint(self, painter, option, index): '''Paints the contact''' # pylint: disable=C0103 model = index.model() painter.save() painter.translate(0, 0) # -> Configure the painter painter.setRenderHint(QtGui.QPainter.Antialiasing) # especially useful for scaled smileys. painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) painter.setClipRect(option.rect) painter.setClipping(True) # -> Draw the skeleton of a ItemView widget: highlighting, selection... QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_ItemViewItem, option, painter, self.parent()) status = model.data(index, Role.StatusRole).toPyObject() text_doc = QtGui.QTextDocument() origin = QtCore.QPointF(0.0, 0.0) if not index.parent().isValid(): # -> Start drawing the text_doc: text_list = self._build_display_role(index, True) painter.translate(QtCore.QPointF(option.rect.topLeft())) # create the text_doc self._put_display_role(text_doc, text_list) # draw the text_doc text_doc.drawContents(painter) else: top_left_point = QtCore.QPointF(option.rect.topLeft()) # a little additional margin # TODO: try to do this for the highlighting too top_left_point.setX(top_left_point.x() + 5) # -> Start drawing the decoration: # calc y_pic_margin = abs((option.rect.height() - self._picture_size)) / 2 x_pic_margin = self._MIN_PICTURE_MARGIN xy_pic_margin = QtCore.QPointF(x_pic_margin, y_pic_margin) # create the picture picture_path = model.data(index, Role.DecorationRole).toString() picture = QtGui.QPixmap(picture_path) if picture.isNull(): picture = QtGui.QPixmap(gui.theme.image_theme.user) else: picture = Utils.pixmap_rounder(picture) #FIXME: when we scale to big sizes status icon is lost by some reason #scale picture scaledpicture = picture.scaled( self._pic_size, transformMode=Qt.SmoothTransformation) # calculate the target position source = QtCore.QRectF(origin, QtCore.QSizeF(scaledpicture.size())) target = QtCore.QRectF(top_left_point + xy_pic_margin, self._pic_sizef) # draw the picture painter.drawPixmap(target, scaledpicture, source) # -> start drawing the 'blocked' emblem if model.data(index, Role.BlockedRole).toPyObject(): source = QtCore.QRectF(origin, QtCore.QSizeF(self.blocked_pic.size())) x_emblem_offset = self._picture_size - self.blocked_pic.size( ).width() y_emblem_offset = self._picture_size - self.blocked_pic.size( ).height() xy_emblem_offset = QtCore.QPointF(x_emblem_offset, y_emblem_offset) target = QtCore.QRectF( top_left_point + xy_pic_margin + xy_emblem_offset, QtCore.QSizeF(self.blocked_pic.size())) painter.drawPixmap(target, self.blocked_pic, source) # -> set-up status picture for calculations picture_path = gui.theme.image_theme.status_icons[model.data( index, Role.StatusRole).toPyObject()] picture_status = QtGui.QPixmap(picture_path) # -> Start setting up the text_doc: text_list = self._build_display_role(index) # set the text into text_doc self._put_display_role(text_doc, text_list) # calculate the vertical offset, to center the text_doc vertically y_text_offset = \ abs(option.rect.height() - text_doc.size().height()) / 2 x_text_offset = 2 * x_pic_margin + self._picture_size xy_text_offset = QtCore.QPointF(x_text_offset, y_text_offset) # move the pointer to the text_doc zone: painter.translate(top_left_point + xy_text_offset) #calculate max text width = treeview width - status image width max_text_width = option.rect.width( ) - 3 * picture_status.size().width() - 2 * x_pic_margin #text width is the min between text_size and max_text_size x_size = min(max_text_width, text_doc.size().width()) #calculate rect size target = QtCore.QRectF( origin, QtCore.QSizeF(x_size, text_doc.size().height())) # draw the text_doc text_doc.drawContents(painter, target) # -> start drawing the status emblem source = QtCore.QRectF(origin, QtCore.QSizeF(picture_status.size())) x_emblem_offset = max_text_width y_emblem_offset = abs( (option.rect.height() - picture_status.size().height())) / 2 xy_emblem_offset = QtCore.QPointF(max_text_width, y_emblem_offset) target = QtCore.QRectF(xy_emblem_offset, QtCore.QSizeF(picture_status.size())) painter.drawPixmap(target, picture_status, source) # -> It's done! painter.restore()