user details box

This commit is contained in:
Max-Wilhelm Bruker 2011-01-10 20:37:34 +01:00
parent 09595cc691
commit 7f7398de6a
12 changed files with 207 additions and 85 deletions

View file

@ -1,8 +1,28 @@
#include "userlist.h"
#include "abstractclient.h"
#include "pixmapgenerator.h"
#include "userinfobox.h"
#include <QHeaderView>
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QMenu>
UserListItemDelegate::UserListItemDelegate(QObject *const parent)
: QItemDelegate(parent)
{
}
bool UserListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
QMouseEvent *const mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::RightButton) {
static_cast<UserList *>(parent())->showContextMenu(mouseEvent->globalPos(), index);
return true;
}
}
return QItemDelegate::editorEvent(event, model, option, index);
}
UserListTWI::UserListTWI()
: QTreeWidgetItem(Type)
@ -18,15 +38,18 @@ bool UserListTWI::operator<(const QTreeWidgetItem &other) const
return data(0, Qt::UserRole).toInt() > other.data(0, Qt::UserRole).toInt();
}
UserList::UserList(bool _global, QWidget *parent)
: QGroupBox(parent), global(_global)
UserList::UserList(AbstractClient *_client, bool _global, QWidget *parent)
: QGroupBox(parent), client(_client), global(_global)
{
itemDelegate = new UserListItemDelegate(this);
userTree = new QTreeWidget;
userTree->setColumnCount(3);
userTree->header()->setResizeMode(QHeaderView::ResizeToContents);
userTree->setHeaderHidden(true);
userTree->setRootIsDecorated(false);
userTree->setIconSize(QSize(20, 12));
userTree->setItemDelegate(itemDelegate);
connect(userTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(userClicked(QTreeWidgetItem *, int)));
QVBoxLayout *vbox = new QVBoxLayout;
@ -87,6 +110,37 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
emit openMessageDialog(item->data(2, Qt::UserRole).toString(), true);
}
void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
{
const QString &userName = index.sibling(index.row(), 2).data(Qt::UserRole).toString();
QAction *aUserName = new QAction(userName, this);
aUserName->setEnabled(false);
QAction *aDetails = new QAction(tr("User &details"), this);
QAction *aChat = new QAction(tr("Direct &chat"), this);
QMenu *menu = new QMenu(this);
menu->addAction(aUserName);
menu->addSeparator();
menu->addAction(aDetails);
menu->addAction(aChat);
QAction *actionClicked = menu->exec(pos);
if (actionClicked == aDetails) {
UserInfoBox *infoWidget = new UserInfoBox(client, true, this, Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
infoWidget->setAttribute(Qt::WA_DeleteOnClose);
infoWidget->setFixedSize(infoWidget->sizeHint());
infoWidget->updateInfo(userName);
infoWidget->show();
} else if (actionClicked == aChat)
emit openMessageDialog(userName, true);
delete menu;
delete aUserName;
delete aDetails;
delete aChat;
}
void UserList::sortItems()
{
userTree->sortItems(1, Qt::AscendingOrder);