37 #include <QListView> |
37 #include <QListView> |
38 #include <QMessageBox> |
38 #include <QMessageBox> |
39 #include <QModelIndexList> |
39 #include <QModelIndexList> |
40 #include <QDebug> |
40 #include <QDebug> |
41 #include <QSortFilterProxyModel> |
41 #include <QSortFilterProxyModel> |
|
42 #include <QMenu> |
42 |
43 |
43 #include "DataManager.h" |
44 #include "DataManager.h" |
44 #include "hwconsts.h" |
45 #include "hwconsts.h" |
45 #include "gameuiconfig.h" |
46 #include "gameuiconfig.h" |
46 #include "playerslistmodel.h" |
47 #include "playerslistmodel.h" |
362 chatNicks->setSelectionMode(QAbstractItemView::SingleSelection); |
363 chatNicks->setSelectionMode(QAbstractItemView::SingleSelection); |
363 chatNicks->setEditTriggers(QAbstractItemView::NoEditTriggers); |
364 chatNicks->setEditTriggers(QAbstractItemView::NoEditTriggers); |
364 chatNicks->setMinimumHeight(10); |
365 chatNicks->setMinimumHeight(10); |
365 chatNicks->setMinimumWidth(10); |
366 chatNicks->setMinimumWidth(10); |
366 chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
367 chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
367 chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu); |
368 chatNicks->setContextMenuPolicy(Qt::CustomContextMenu); |
|
369 |
368 connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)), |
370 connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)), |
369 this, SLOT(chatNickDoubleClicked(QListWidgetItem *))); |
371 this, SLOT(chatNickDoubleClicked(QListWidgetItem *))); |
370 connect(chatNicks, SIGNAL(currentRowChanged(int)), |
372 |
371 this, SLOT(chatNickSelected(int))); |
373 connect(chatNicks, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(nicksContextMenuRequested(QPoint))); |
372 |
374 |
373 mainLayout.addWidget(chatNicks, 0, 1, 3, 1); |
375 mainLayout.addWidget(chatNicks, 0, 1, 3, 1); |
374 |
376 |
375 // the userData is used to flag things that are even available when user |
377 // the userData is used to flag things that are even available when user |
376 // is offline |
378 // is offline |
707 /*chatNicks->addItem(item);*/ |
712 /*chatNicks->addItem(item);*/ |
708 |
713 |
709 if ((!isIgnored) && (nick != m_userNick)) // don't auto-complete own name |
714 if ((!isIgnored) && (nick != m_userNick)) // don't auto-complete own name |
710 chatEditLine->addNickname(nick); |
715 chatEditLine->addNickname(nick); |
711 |
716 |
712 //emit nickCountUpdate(chatNicks->count()); |
717 emit nickCountUpdate(chatNicks->model()->rowCount()); |
713 |
718 |
714 if(notifyNick && notify && gameSettings->value("frontend/sound", true).toBool()) |
719 if(notifyNick && notify && gameSettings->value("frontend/sound", true).toBool()) |
715 { |
720 { |
716 SDLInteraction::instance().playSoundFile( |
721 SDLInteraction::instance().playSoundFile( |
717 m_helloSounds.at(rand() % m_helloSounds.size())); |
722 m_helloSounds.at(rand() % m_helloSounds.size())); |
909 m_clickedNick = ""; |
914 m_clickedNick = ""; |
910 QList<QAction *> actions = chatNicks->actions(); |
915 QList<QAction *> actions = chatNicks->actions(); |
911 actions.first()->activate(QAction::Trigger); |
916 actions.first()->activate(QAction::Trigger); |
912 } |
917 } |
913 |
918 |
914 void HWChatWidget::chatNickSelected(int index) |
919 void HWChatWidget::chatNickSelected() |
915 { |
920 { |
916 Q_UNUSED(index); |
|
917 |
|
918 /*QListWidgetItem* item = chatNicks->currentItem(); |
|
919 QString nick = ""; |
|
920 if (item != NULL) |
|
921 nick = item->text(); |
|
922 else |
|
923 nick = m_clickedNick; |
|
924 |
|
925 // don't display all actions for own nick |
|
926 bool isSelf = (nick == m_userNick); |
|
927 |
|
928 acFollow->setVisible(!isSelf); |
|
929 |
|
930 // update context menu labels according to possible action |
|
931 if(ignoreList.contains(nick, Qt::CaseInsensitive)) |
|
932 { |
|
933 acIgnore->setText(QAction::tr("Unignore")); |
|
934 acIgnore->setIcon(QIcon(":/res/unignore.png")); |
|
935 } |
|
936 else |
|
937 { |
|
938 acIgnore->setText(QAction::tr("Ignore")); |
|
939 acIgnore->setIcon(QIcon(":/res/ignore.png")); |
|
940 acIgnore->setVisible(!isSelf); |
|
941 } |
|
942 |
|
943 if(friendsList.contains(nick, Qt::CaseInsensitive)) |
|
944 { |
|
945 acFriend->setText(QAction::tr("Remove friend")); |
|
946 acFriend->setIcon(QIcon(":/res/remfriend.png")); |
|
947 } |
|
948 else |
|
949 { |
|
950 acFriend->setText(QAction::tr("Add friend")); |
|
951 acFriend->setIcon(QIcon(":/res/addfriend.png")); |
|
952 acFriend->setVisible(!isSelf); |
|
953 } |
|
954 |
|
955 if (m_isAdmin) |
|
956 { |
|
957 acKick->setVisible(!isSelf); |
|
958 acBan->setVisible(!isSelf); |
|
959 }*/ |
|
960 } |
921 } |
961 |
922 |
962 void HWChatWidget::setStatus(const QString & nick, ListWidgetNickItem::StateFlag flag, bool status) |
923 void HWChatWidget::setStatus(const QString & nick, ListWidgetNickItem::StateFlag flag, bool status) |
963 { |
924 { |
964 /*QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly); |
925 /*QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly); |
1124 } |
1085 } |
1125 |
1086 |
1126 |
1087 |
1127 void HWChatWidget::setUsersModel(QAbstractItemModel *model) |
1088 void HWChatWidget::setUsersModel(QAbstractItemModel *model) |
1128 { |
1089 { |
|
1090 chatNicks->selectionModel()->deleteLater(); |
|
1091 |
1129 chatNicks->setModel(model); |
1092 chatNicks->setModel(model); |
1130 chatNicks->setModelColumn(0); |
1093 chatNicks->setModelColumn(0); |
1131 } |
1094 |
|
1095 connect(chatNicks->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), |
|
1096 this, SLOT(chatNickSelected())); |
|
1097 } |
|
1098 |
|
1099 void HWChatWidget::nicksContextMenuRequested(const QPoint &pos) |
|
1100 { |
|
1101 QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
|
1102 |
|
1103 QString nick; |
|
1104 |
|
1105 if(mil.size()) |
|
1106 nick = mil[0].data().toString(); |
|
1107 else |
|
1108 nick = m_clickedNick; |
|
1109 |
|
1110 QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(chatNicks->model()); |
|
1111 if(!playersSortFilterModel) |
|
1112 return; |
|
1113 |
|
1114 PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel()); |
|
1115 |
|
1116 if(!players) |
|
1117 return; |
|
1118 |
|
1119 bool isSelf = (nick == m_userNick); |
|
1120 |
|
1121 acFollow->setVisible(!isSelf); |
|
1122 |
|
1123 // update context menu labels according to possible action |
|
1124 if(players->isFlagSet(nick, PlayersListModel::Ignore)) |
|
1125 { |
|
1126 acIgnore->setText(QAction::tr("Unignore")); |
|
1127 acIgnore->setIcon(QIcon(":/res/unignore.png")); |
|
1128 } |
|
1129 else |
|
1130 { |
|
1131 acIgnore->setText(QAction::tr("Ignore")); |
|
1132 acIgnore->setIcon(QIcon(":/res/ignore.png")); |
|
1133 acIgnore->setVisible(!isSelf); |
|
1134 } |
|
1135 |
|
1136 if(players->isFlagSet(nick, PlayersListModel::Friend)) |
|
1137 { |
|
1138 acFriend->setText(QAction::tr("Remove friend")); |
|
1139 acFriend->setIcon(QIcon(":/res/remfriend.png")); |
|
1140 } |
|
1141 else |
|
1142 { |
|
1143 acFriend->setText(QAction::tr("Add friend")); |
|
1144 acFriend->setIcon(QIcon(":/res/addfriend.png")); |
|
1145 acFriend->setVisible(!isSelf); |
|
1146 } |
|
1147 |
|
1148 if (m_isAdmin) |
|
1149 { |
|
1150 acKick->setVisible(!isSelf); |
|
1151 acBan->setVisible(!isSelf); |
|
1152 } |
|
1153 |
|
1154 m_nicksMenu->clear(); |
|
1155 |
|
1156 foreach(QAction * action, chatNicks->actions()) |
|
1157 m_nicksMenu->addAction(action); |
|
1158 |
|
1159 m_nicksMenu->popup(chatNicks->mapToGlobal(pos)); |
|
1160 } |