sort nick lists case-insensitive
authorsheepluva
Sat, 29 Jan 2011 01:08:39 +0100
changeset 4876 813ef4e8e385
parent 4875 2a37a0e0892d
child 4877 746ddd590dee
sort nick lists case-insensitive
QTfrontend/chatwidget.cpp
QTfrontend/chatwidget.h
--- a/QTfrontend/chatwidget.cpp	Fri Jan 28 03:30:14 2011 +0100
+++ b/QTfrontend/chatwidget.cpp	Sat Jan 29 01:08:39 2011 +0100
@@ -32,6 +32,14 @@
 #include "gameuiconfig.h"
 #include "chatwidget.h"
 
+ListWidgetNickItem::ListWidgetNickItem(const QString& nick) : QListWidgetItem(nick) {}
+
+bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const
+{
+    // case in-sensitive comparison of the associated strings
+    return (text().compare(other.text(), Qt::CaseInsensitive) < 0);
+}
+
 HWChatWidget::HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify) :
   QWidget(parent),
   mainLayout(this)
@@ -241,7 +249,7 @@
 
 void HWChatWidget::nickAdded(const QString& nick, bool notifyNick)
 {
-    QListWidgetItem * item = new QListWidgetItem(nick);
+    QListWidgetItem * item = new ListWidgetNickItem(nick);
     updateIcon(item);
     chatNicks->addItem(item);
 
--- a/QTfrontend/chatwidget.h	Fri Jan 28 03:30:14 2011 +0100
+++ b/QTfrontend/chatwidget.h	Sat Jan 29 01:08:39 2011 +0100
@@ -26,12 +26,21 @@
 
 #include "SDLs.h"
 
+class ListWidgetNickItem;
 class QTextBrowser;
 class QLineEdit;
 class QListWidget;
 class QSettings;
 class SDLInteraction;
 
+// this class is for custom nick sorting
+class ListWidgetNickItem : public QListWidgetItem
+{
+public:
+  ListWidgetNickItem(const QString& nick);
+  bool operator<(const QListWidgetItem & other) const;
+};
+
 class HWChatWidget : public QWidget
 {
   Q_OBJECT