def send_message(self, formatter, my_account, text, cedict, cedir, first): '''This method is called from the core, when a message is sent by us. It shows the message''' self._append_to_chat('<b>ME:</b>') self._append_to_chat(Utils.parse_emotes(Utils.escape(unicode(text)))) self._append_to_chat('<br/>')
def _set_information(self, lines): message, account = lines message = Utils.escape(message) message = Utils.parse_emotes(unicode(message)) message = u'%s<br /><span style="font-size: small;">%s</span>' % ( message, account) self._message_lbl.setText(message)
def set_message(self, message): '''Updates the message''' message = Utils.escape(message) message = Utils.parse_emotes(unicode(message)) message = message + ( u'<br /><span style="font-size: small;">[%s]</span>' % self._account) self._message_lbl.setText(message)
def select_color(cls, color, callback): '''select color, receives a e3.Message.Color with the current color the callback receives a new color object woth the new selection ''' qt_color = Utils.e3_color_to_qcolor(color) new_qt_color = QtGui.QColorDialog.getColor(qt_color) if new_qt_color.isValid() and not new_qt_color == qt_color: color = Utils.qcolor_to_e3_color(new_qt_color) callback(color)
def update_single_information(self, nick, message, account): # emesene's """This method is called from the core (e3 or base class or whatever to update the contacts infos""" # account is a string containing the email # does this have to update the picture too? log.debug("UPSingInfo Start") status = self._session.contacts.get(account).status log.debug("UpSingInfo: [%s], [%s], [%s], [%s]" % (status, nick, message, account)) self._widget_d["info_panel"].set_all(status, Utils.unescape(nick), Utils.unescape(message), account) log.debug("UPSingInfo Stop")
def _format_contact_display_role(text): """Formats correctly a string part of a display role. Parses emotes, and scales them.""" # TODO: calculate smiley size from text's size. smiley_size = 16 text = Utils.escape(text) text = replace_markup(text) text = Utils.parse_emotes(unicode(text)) text = text.replace("<img src", '<img width="%d" height="%d" src' % (smiley_size, smiley_size)) return text
def update(self, status, display_name, message, account): '''Updates the infos shown in the panel''' pixmap = QtGui.QPixmap(gui.theme.status_icons[status]) #display_name = Utils.escape(display_name) display_name = Utils.parse_emotes(unicode(display_name + u' ' \ u'[' + account + u']')) #message = Utils.escape(message) message = Utils.parse_emotes(unicode(message)) self._emblem_lbl.setPixmap(pixmap) self._display_name_lbl.setText(display_name) self._message_lbl.setText(message)
def receive_message(self, formatter, contact, message, cedict, cedir, first): '''This method is called from the core (e3 or base class or whatever when a new message arrives. It shows the new message''' log.debug('%s, %s, %s, %s, %s, %s' % (formatter,contact, message.type, message.account, cedict, first) ) self._append_to_chat( Utils.parse_emotes(u'<b>' + contact.display_name + u':</b>')) self._append_to_chat( Utils.parse_emotes(Utils.escape(unicode(message.body))), message.style) self._append_to_chat('<br>')
def set_text(self, text): '''Displays the given text''' #NOTE: do we have to set also the QLineEdit's text? #<-> method could be called while the QLEdit is active? self._text = unicode(text) text = Utils.escape(unicode(text)) parsed_text = Utils.parse_emotes(text) text = QtCore.QString(text) if not text.isEmpty(): self._is_empty_message_displayed = False self.label.setText(parsed_text) elif self._allow_empty: self._is_empty_message_displayed = True self.label.setText(self._empty_message)
def receive_message(self, formatter, contact, message, cedict, cedir, first): '''This method is called from the core (e3 or base class or whatever when a new message arrives. It shows the new message''' log.debug( '%s, %s, %s, %s, %s, %s' % (formatter, contact, message.type, message.account, cedict, first)) self._append_to_chat( Utils.parse_emotes(u'<b>' + contact.display_name + u':</b>')) self._append_to_chat( Utils.parse_emotes(Utils.escape(unicode(message.body))), message.style) self._append_to_chat('<br>')
def _set_contact_info(self, contact_item, contact): '''Fills the contact Item with data''' display_name = Utils.escape(unicode(contact.display_name)) message = Utils.escape(unicode(contact.message)) sort_role = self.sort_role_dict[contact.status] + display_name contact_item.setData(display_name, Role.DisplayRole) contact_item.setData(message, Role.MessageRole) contact_item.setData(contact.picture, Role.DecorationRole) contact_item.setData(contact.media, Role.MediaRole) contact_item.setData(contact.status, Role.StatusRole) contact_item.setData(contact.blocked, Role.BlockedRole) contact_item.setData(contact.account, Role.ToolTipRole) contact_item.setData(sort_role, Role.SortRole) contact_item.setData(contact, Role.DataRole)
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 clear(self, source="", target="", target_display="", source_img="", target_img=""): """clear the content""" body = self.theme.get_body(source, target, target_display, source_img, target_img) url = QtCore.QUrl(Utils.path_to_url(self.theme.path)) self._qwebview.setHtml(body, url) gui.base.OutputText.clear(self) self.ready = False
def _set_contact_info(self, contact_item, contact): '''Fills the contact Item with data''' # TODO: handle moving contact between groups # in particular: online/offiline display_name = Utils.escape(unicode(contact.display_name)) message = Utils.escape(unicode(contact.message)) sort_role = self.sort_role_dict[contact.status] + display_name contact_item.setData(display_name, Role.DisplayRole) contact_item.setData(message, Role.MessageRole) contact_item.setData(contact.picture, Role.DecorationRole) contact_item.setData(contact.media, Role.MediaRole) contact_item.setData(contact.status, Role.StatusRole) contact_item.setData(contact.blocked, Role.BlockedRole) contact_item.setData(contact.account, Role.ToolTipRole) contact_item.setData(sort_role, Role.SortRole) contact_item.setData(contact, Role.DataRole)
def _set_contact_info(self, contact_item, contact): """Fills the contact Item with data""" # TODO: handle moving contact between groups # in particular: online/offiline display_name = Utils.escape(unicode(contact.display_name)) message = Utils.escape(unicode(contact.message)) sort_role = self.sort_role_dict[contact.status] + display_name contact_item.setData(display_name, Role.DisplayRole) contact_item.setData(message, Role.MessageRole) contact_item.setData(contact.picture, Role.DecorationRole) contact_item.setData(contact.media, Role.MediaRole) contact_item.setData(contact.status, Role.StatusRole) contact_item.setData(contact.blocked, Role.BlockedRole) contact_item.setData(contact.account, Role.ToolTipRole) contact_item.setData(sort_role, Role.SortRole) contact_item.setData(contact, Role.DataRole)
def select_font(cls, style, callback): '''select font and if available size and style, receives a e3.Message.Style object with the current style the callback receives a new style object with the new selection ''' new_qt_font, result = QtGui.QFontDialog.getFont() if result: estyle = Utils.qfont_to_style(new_qt_font, style.color) callback(estyle)
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 add_group(self, group): '''Add a group.''' if not self._config.b_order_by_group: return new_group_item = QtGui.QStandardItem(Utils.escape(unicode(group.name))) new_group_item.setData(group.identifier, Role.UidRole) new_group_item.setData(0, Role.TotalCountRole) new_group_item.setData(0, Role.OnlCountRole) new_group_item.setData(group, Role.DataRole) self.appendRow(new_group_item)
def add_group(self, group, force=False): '''Add a group.''' if not (force or self._order_by_group): return new_group_item = QtGui.QStandardItem(Utils.escape(unicode(group.name))) new_group_item.setData(group.identifier, Role.UidRole) new_group_item.setData(group, Role.DataRole) self.appendRow(new_group_item) return new_group_item
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 add_group(self, group): """Add a group.""" if not self._config.b_order_by_group: return new_group_item = QtGui.QStandardItem(Utils.escape(unicode(group.name))) new_group_item.setData(group.identifier, Role.UidRole) new_group_item.setData(0, Role.TotalCountRole) new_group_item.setData(0, Role.OnlCountRole) new_group_item.setData(group, Role.DataRole) self.appendRow(new_group_item)
def _show_record(self, record): '''Appends a record in the view''' time_string = time.localtime(float(record.created)) time_string = time.strftime("%H:%M:%S", time_string) html = u'<small>(%s): [<b>%s</b>] : ' html = html % (time_string, record.name) try: html = html + '%s</small><br />' % Utils.escape(record.msg.strip()) except AttributeError as detail: html = html + '<small><i><<message insertion failed [%s:%s]>></i></small><br>' % (type(record.msg), str(record.msg)) self._cursor.insertHtml(html)
def update_single_information(self, nick, message, account): # emesene's '''This method is called from the core (e3 or base class or whatever to update the contacts infos''' # account is a string containing the email # does this have to update the picture too? log.debug('UPSingInfo Start') status = self.session.contacts.get(account).status log.debug('UpSingInfo: [%s], [%s], [%s], [%s]' % (status, nick, message, account)) self._widget_d['info_panel'].set_all(Utils.unescape(message), account) log.debug('UPSingInfo Stop')
def add_group(self, group, force=False): '''Add a group.''' if not (force or self._order_by_group): return new_group_item = QtGui.QStandardItem( Utils.escape(unicode(group.name))) new_group_item.setData(group.identifier, Role.UidRole) new_group_item.setData(group, Role.DataRole) self.appendRow(new_group_item) return new_group_item
def _show_record(self, record): '''Appends a record in the view''' time_string = time.localtime(float(record.created)) time_string = time.strftime("%H:%M:%S", time_string) html = u'<small>(%s): [<b>%s</b>] : ' html = html % (time_string, record.name) try: html = html + '%s</small><br />' % Utils.escape(record.msg.strip()) except AttributeError as detail: html = html + '<small><i><<message insertion failed [%s:%s]>></i></small><br>' % ( type(record.msg), str(record.msg)) self._cursor.insertHtml(html)
def _set_e3_style(self, e3_style): '''Sets the font style, given an e3 style''' qt_color = Utils.e3_color_to_qcolor(e3_style.color) qt_font = QtGui.QFont() qt_font.setFamily( e3_style.font ) qt_font.setBold( e3_style.bold ) qt_font.setItalic( e3_style.italic ) qt_font.setStrikeOut( e3_style.strike ) qt_font.setPointSize( e3_style.size ) self._set_qt_color(qt_color) self._set_qt_font(qt_font)
def _set_e3_style(self, e3_style): '''Sets the font style, given an e3 style''' qt_color = Utils.e3_color_to_qcolor(e3_style.color) qt_font = QtGui.QFont() qt_font.setFamily(e3_style.font) qt_font.setBold(e3_style.bold) qt_font.setItalic(e3_style.italic) qt_font.setStrikeOut(e3_style.strike) qt_font.setPointSize(e3_style.size) self._set_qt_color(qt_color) self._set_qt_font(qt_font)
def clear(self, source="", target="", target_display="", source_img="", target_img=""): '''clear the content''' body = self.theme.get_body(source, target, target_display, source_img, target_img) url = QtCore.QUrl(Utils.path_to_url(self.theme.path)) self._qwebview.setHtml(body, url) gui.base.OutputText.clear(self) self.ready = False
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 _format_contact_display_role(text): '''Formats correctly a string part of a display role. Parses emotes, and scales them.''' # TODO: calculate smiley size from text's size. smiley_size = 16 #text = Utils.escape(text) #log.debug(text) text = replace_markup(text) # temporary stuff: text = Plus.msnplus_strip(text) text = text.replace('[C=c10ud]', '') text = Utils.parse_emotes(unicode(text)) text = text.replace('<img src', '<img width="%d" height="%d" src' % (smiley_size, smiley_size)) #log.debug(text) return text
def _format_contact_display_role(text): '''Formats correctly a string part of a display role. Parses emotes, and scales them.''' # TODO: calculate smiley size from text's size. smiley_size = 16 #text = Utils.escape(text) #log.debug(text) text = replace_markup(text) # temporary stuff: text = Plus.msnplus_strip(text) text = text.replace('[C=c10ud]', '') text = Utils.parse_emotes(unicode(text)) text = text.replace( '<img src', '<img width="%d" height="%d" src' % (smiley_size, smiley_size)) #log.debug(text) return text
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 _build_display_role(self, index, is_group=False): """Build a string to be used as item's display role""" model = index.model() data_role = model.data(index, Role.DataRole).toPyObject() if is_group: name = model.data(index, Role.DisplayRole).toPyObject() name = Utils.escape(name) online = model.data(index, Role.OnlCountRole).toPyObject() total = model.data(index, Role.TotalCountRole).toPyObject() display_role = self._config.group_template display_role = replace_markup(display_role) display_role = display_role.replace("[$NAME]", name) display_role = display_role.replace("[$ONLINE_COUNT]", str(online)) display_role = display_role.replace("[$TOTAL_COUNT]", str(total)) else: # TODO: consider changing how data is stored inside the model, # if useful display_role = self._format_nick( data_role, ( str(model.data(index, Role.DisplayRole).toPyObject()), data_role.nick, str(model.data(index, Role.MessageRole).toPyObject()), ), ) display_role = _format_contact_display_role(display_role) # message = model.data(index, Role.MessageRole).toString() # if not message.isEmpty(): # display_role += u'<p style="-qt-paragraph-type:empty; ' \ # u'margin-top:5px; margin-bottom:0px; ' \ # u'margin-left:0px; margin-right:0px; ' \ # u'-qt-block-indent:0; text-indent:0px;"></p>' # message = u'<i>' + message + u'</i>' # display_role += _format_contact_display_role(message) # display_role = _format_contact_display_role(display_role) # display_role += '</table>' return display_role
def _get_e3_style(self): '''Returns the font style in e3 format''' qt_font = self._get_qt_font() e3_color = Utils.qcolor_to_e3_color(self._qt_color) e3_style = Utils.qfont_to_style(qt_font, e3_color) return e3_style
def information(self, formatter, contact, message): '''This method is called by the core, when there's the need to display an information message''' self._append_to_chat( Utils.parse_emotes('<p align="right"><i>' + Utils.escape(unicode(message)) + '</i></p>'))
def set_nick(self, nick): '''Updates the nick''' nick = Utils.escape(nick) nick = Utils.parse_emotes(unicode(nick)) nick = nick + (u' [%s]' % self._account) self._display_name_lbl.setText(nick)
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 set_message(self, message): '''Updates the message''' message = Utils.escape(message) message = Utils.parse_emotes(unicode(message)) message = message + (u'<br /><span style="font-size: small;">[%s]</span>' % self._account) self._message_lbl.setText(message)
def handle_entityref(self, name): self._data += Utils.unescape(u'&%s;' % name)
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 information(self, formatter, contact, message): '''This method is called by the core, when there's the need to display an information message''' self._append_to_chat(Utils.parse_emotes('<p align="right"><i>' + Utils.escape(unicode(message)) + '</i></p>'))
def set_message(self, message): '''Updates the message''' message = Utils.escape(message) message = Utils.parse_emotes(unicode(message)) self._message_lbl.setText(message)
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()