From 02cba1c1c40e9615b07e3ef80b84928db8b19fea Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 17 Dec 2011 16:22:33 +0100 Subject: [PATCH] Add auto-resize of nicklist on insertItem/clear, set NoFocus on title, add bullets for nicklist --- data/icons/bullet_green_8x8.png | Bin 0 -> 384 bytes data/icons/bullet_yellow_8x8.png | Bin 0 -> 375 bytes src/qweechat/buffer.py | 39 +++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 data/icons/bullet_green_8x8.png create mode 100644 data/icons/bullet_yellow_8x8.png diff --git a/data/icons/bullet_green_8x8.png b/data/icons/bullet_green_8x8.png new file mode 100644 index 0000000000000000000000000000000000000000..ea8095361fb862c70eb6cb8f6ffff585995070c1 GIT binary patch literal 384 zcmWlVJuCxp7{=fC?(f>W=JYt1lxo8u(J%;uU=UKNhDeo#h1hJwE@2U|NGu`-12Hie zBqUfG>BP_wUlH20zQ0OcPwxJI*Sz_?PoDS9vpn;WzK|?cNB|&*yMs|%odukNy<_gf z1zT_`8tR1YlgcOC2xC2=Ah5!$9c(Vy7jdF{XbQlk7C=~8_1F|*t z$2p=qW;9ftMv=kJ*%`c&H>L>+$X<0osF&J^MOo`5e+6&!8D+~2d8%WEJpxrx1BT56 z4M>%ixl4S+%M?yQgZ+Vk0wljOS^8;8oSCtf+<66RNDVeR8lX-HfS>n5?l|{gri^?3 zH<7#6eW1xgah1fm#D|ZU@BQ7Q+sEmfJ<#bs+FbxhTp3n5+6i*aR@M}0#<&9u;`Zm1 VADNt6-dHbG3gNE4;CAQe>_4R>k1zlL literal 0 HcmV?d00001 diff --git a/data/icons/bullet_yellow_8x8.png b/data/icons/bullet_yellow_8x8.png new file mode 100644 index 0000000000000000000000000000000000000000..58ad5cf346e549fe49eb1f5ae7095b66e00765e2 GIT binary patch literal 375 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-7A{X0#}J9jtOxzQnH(k9AKc$#{rKEERyA!$ zb=!&;I!aR?txPU?At&2p=i2^@#qr|W{tKoniWAx$Ja(<M|c|3vzDc2lqR2)pL+Ur^(4!irYCtKxE@a6&z^p0hUOHWqG>yoW(})MEMB=>Z^b5f~&pmFi#h;1cQYKfI>v}zosW-1wEDpTmFSLgt;~#Tse6fLf T$i^&SP%(JA`njxgN@xNAV&9t! literal 0 HcmV?d00001 diff --git a/src/qweechat/buffer.py b/src/qweechat/buffer.py index 5b9acee..4626461 100644 --- a/src/qweechat/buffer.py +++ b/src/qweechat/buffer.py @@ -44,10 +44,26 @@ class GenericListWidget(QtGui.QListWidget): pal.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('black')) self.setPalette(pal) + def auto_resize(self): + size = self.sizeHintForColumn(0) + if size > 0: + size += 4 + self.setMaximumWidth(size) + + def clear(self, *args): + """Re-implement clear to set dynamic size after clear.""" + apply(QtGui.QListWidget.clear, (self,) + args) + self.auto_resize() + def addItem(self, *args): """Re-implement addItem to set dynamic size after add.""" apply(QtGui.QListWidget.addItem, (self,) + args) - self.setMaximumWidth(self.sizeHintForColumn(0) + 4) + self.auto_resize() + + def insertItem(self, *args): + """Re-implement insertItem to set dynamic size after insert.""" + apply(QtGui.QListWidget.insertItem, (self,) + args) + self.auto_resize() class BufferListWidget(GenericListWidget): @@ -77,6 +93,7 @@ class BufferWidget(QtGui.QWidget): # title self.title = QtGui.QLineEdit() + self.title.setFocusPolicy(QtCore.Qt.NoFocus) # splitter with chat + nicklist self.chat_nicklist = QtGui.QSplitter() @@ -126,6 +143,7 @@ class Buffer(QtCore.QObject): def __init__(self, data={}): QtCore.QObject.__init__(self) self.data = data + self.nicklist = [] self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0)) if self.data and self.data['title']: self.widget.set_title(self.data['title']) @@ -142,4 +160,21 @@ class Buffer(QtCore.QObject): def add_nick(self, prefix, nick): """Add a nick to nicklist.""" - self.widget.nicklist.addItem('%s%s' % (prefix, nick)) + prefix_color = { '': '', ' ': '', '+': 'yellow' } + self.nicklist.append((prefix, nick)) + color = prefix_color.get(prefix, 'green') + if color: + icon = QtGui.QIcon('data/icons/bullet_%s_8x8.png' % color) + else: + pixmap = QtGui.QPixmap(8, 8) + pixmap.fill() + icon = QtGui.QIcon(pixmap) + item = QtGui.QListWidgetItem(icon, nick) + #item.setFont('monospace') + self.widget.nicklist.addItem(item) + self.widget.nicklist.setVisible(True) + + def remove_all_nicks(self): + """Remove all nicks from nicklist.""" + self.nicklist = [] + self.widget.nicklist.clear()