From b39f73befca9eb06bdd8ac601dfafd451a6eb7b8 Mon Sep 17 00:00:00 2001 From: Benjamin Jemlich Date: Thu, 24 Dec 2009 19:36:45 +0100 Subject: [PATCH] Remove the flags column and draw the flags icons right aligned --- src/mumble/MainWindow.cpp | 2 - src/mumble/MainWindow.ui | 6 +++ src/mumble/UserModel.cpp | 16 +++---- src/mumble/UserView.cpp | 90 +++++++++++++++++++++++---------------- src/mumble/UserView.h | 3 +- 5 files changed, 70 insertions(+), 47 deletions(-) diff --git a/src/mumble/MainWindow.cpp b/src/mumble/MainWindow.cpp index ff17728bdaf..d80d806e42d 100644 --- a/src/mumble/MainWindow.cpp +++ b/src/mumble/MainWindow.cpp @@ -304,7 +304,6 @@ void MainWindow::setupGui() { restoreState(g.s.qbaMainWindowState); g.s.wlWindowLayout = wlTmp; - qtvUsers->header()->restoreState(g.s.qbaHeaderState); setupView(false); qmTray = new QMenu(this); @@ -690,7 +689,6 @@ void MainWindow::setupView(bool toggle_minimize) { qdwLog->setVisible(showit); qdwChat->setVisible(showit && g.s.bShowChatbar); - qtvUsers->header()->setVisible(showit); menuBar()->setVisible(showit); if (toggle_minimize) { diff --git a/src/mumble/MainWindow.ui b/src/mumble/MainWindow.ui index a4632459be0..6f9aa2b2a95 100644 --- a/src/mumble/MainWindow.ui +++ b/src/mumble/MainWindow.ui @@ -38,6 +38,12 @@ true + + true + + + false + diff --git a/src/mumble/UserModel.cpp b/src/mumble/UserModel.cpp index 1be984f138f..0b68e6b906e 100644 --- a/src/mumble/UserModel.cpp +++ b/src/mumble/UserModel.cpp @@ -243,7 +243,7 @@ UserModel::~UserModel() { int UserModel::columnCount(const QModelIndex &) const { - return 2; + return 1; } QModelIndex UserModel::index(int row, int column, const QModelIndex &p) const { @@ -388,10 +388,8 @@ QVariant UserModel::data(const QModelIndex &idx, int role) const { else return p->qsName; } - if (! p->qsFriendName.isEmpty()) - l << qiFriend; - if (p->iId >= 0) - l << qiAuthenticated; + if (! p->qsComment.isEmpty()) + l << (item->bCommentSeen ? qiCommentSeen : qiComment); if (p->bMute) l << qiMutedServer; if (p->bSuppress) @@ -404,8 +402,10 @@ QVariant UserModel::data(const QModelIndex &idx, int role) const { l << qiDeafenedServer; if (p->bSelfDeaf) l << qiDeafenedSelf; - if (! p->qsComment.isEmpty()) - l << (item->bCommentSeen ? qiCommentSeen : qiComment); + if (p->iId >= 0) + l << qiAuthenticated; + if (! p->qsFriendName.isEmpty()) + l << qiFriend; return l; default: break; @@ -1165,7 +1165,7 @@ void UserModel::userTalkingChanged() { void UserModel::userMuteDeafChanged() { ClientUser *p=static_cast(sender()); - QModelIndex idx = index(p, 1); + QModelIndex idx = index(p); emit dataChanged(idx, idx); if (g.uiSession && (p->cChannel == ClientUser::get(g.uiSession)->cChannel)) updateOverlay(); diff --git a/src/mumble/UserView.cpp b/src/mumble/UserView.cpp index b2483cdb6c9..1245fb82ce7 100644 --- a/src/mumble/UserView.cpp +++ b/src/mumble/UserView.cpp @@ -60,37 +60,57 @@ UserDelegate::UserDelegate(QObject *p) : QStyledItemDelegate(p) { } -QSize UserDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - if (index.column() == 1) { - const QAbstractItemModel *m = index.model(); - QVariant data = m->data(index); - QList ql = data.toList(); - return QSize(18 * ql.count(), 18); - } else { - return QStyledItemDelegate::sizeHint(option, index); +void UserDelegate::paint(QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { + const QAbstractItemModel *m = index.model(); + const QModelIndex idxc1 = index.sibling(index.row(), 1); + QVariant data = m->data(idxc1); + QList ql = data.toList(); + + painter->save(); + + QStyleOptionViewItemV4 o = option; + initStyleOption(&o, index); + + // draw background + o.widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &o, painter, o.widget); + + // resize rect to exclude the flag icons + o.rect = option.rect.adjusted(0, 0, -18 * ql.count(), 0); + + // remove focus state + o.state &= ~QStyle::State_Selected; + o.state &= ~QStyle::State_MouseOver; + + o.widget->style()->drawControl(QStyle::CE_ItemViewItem, &o, painter, o.widget); + + QRect ps = QRect(option.rect.right() - (ql.size() * 18), option.rect.y(), ql.size() * 18, option.rect.height()); + for (int i = 0; i < ql.size(); ++i) { + QRect r = ps; + r.setSize(QSize(16, 16)); + r.translate(i * 18 + 1, 1); + QPixmap pixmap = (qvariant_cast(ql[i]).pixmap(QSize(16, 16))); + QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmap.size(), r).topLeft(); + painter->drawPixmap(p, pixmap); } + + painter->restore(); } -void UserDelegate::paint(QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - if (index.column() == 1) { +bool UserDelegate::helpEvent(QHelpEvent *evt, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) { + if (index.isValid()) { const QAbstractItemModel *m = index.model(); - QVariant data = m->data(index); + const QModelIndex idxc1 = index.sibling(index.row(), 1); + QVariant data = m->data(idxc1); QList ql = data.toList(); + int offset = 0; + offset = ql.size() * 18; + offset = option.rect.topRight().x() - offset; - painter->save(); - for (int i=0;i(ql[i]).pixmap(QSize(16,16))); - QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmap.size(), r).topLeft(); - painter->drawPixmap(p, pixmap); + if (evt->pos().x() >= offset) { + return QStyledItemDelegate::helpEvent(evt, view, option, idxc1); } - painter->restore(); - return; - } else { - QStyledItemDelegate::paint(painter,option,index); } + return QStyledItemDelegate::helpEvent(evt, view, option, index); } UserView::UserView(QWidget *p) : QTreeView(p) { @@ -119,42 +139,40 @@ void UserView::mouseReleaseEvent(QMouseEvent *evt) { QPoint qpos = evt->pos(); QModelIndex idx = indexAt(qpos); - if ((evt->button() == Qt::LeftButton) && idx.isValid() && (idx.column() == 1)) { + if ((evt->button() == Qt::LeftButton) && idx.isValid()) { UserModel *um = static_cast(model()); ClientUser *cu = um->getUser(idx); Channel * c = um->getChannel(idx); if ((cu && ! cu->qsComment.isEmpty()) || (! cu && c && ! c->qsDesc.isEmpty())) { QRect r = visualRect(idx); - qpos = qpos - r.topLeft(); - int offset = 0; + int offset = 18; if (cu) { // Calculate pixel offset of comment flag - if (! cu->qsFriendName.isEmpty()) - offset += 18; - if (cu->iId >= 0) - offset += 18; if (cu->bMute) offset += 18; if (cu->bSuppress) offset += 18; - if (cu->bDeaf) - offset += 18; if (cu->bSelfMute) offset += 18; + if (cu->bLocalMute) + offset += 18; if (cu->bSelfDeaf) offset += 18; - if (cu->bLocalMute) + if (cu->bDeaf) + offset += 18; + if (! cu->qsFriendName.isEmpty()) + offset += 18; + if (cu->iId >= 0) offset += 18; } + offset = r.topRight().x() - offset; + if ((qpos.x() >= offset) && (qpos.x() <= (offset+18))) { // Clicked on comment flag - QModelIndex midx = idx.sibling(idx.row(), 0); - r = r.united(visualRect(midx)); - r.setWidth(r.width() / 2); QWhatsThis::showText(viewport()->mapToGlobal(r.bottomRight()), Log::validHtml(cu ? cu->qsComment : c->qsDesc), this); um->seenComment(idx); return; diff --git a/src/mumble/UserView.h b/src/mumble/UserView.h index 4cd8542b38c..c5d16338bca 100644 --- a/src/mumble/UserView.h +++ b/src/mumble/UserView.h @@ -41,8 +41,9 @@ class UserDelegate : public QStyledItemDelegate { Q_DISABLE_COPY(UserDelegate) public: UserDelegate(QObject *parent = NULL); - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; void paint(QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + public slots: + bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index); }; class UserView : public QTreeView {