Skip to content

Commit

Permalink
Remove the flags column and draw the flags icons right aligned
Browse files Browse the repository at this point in the history
  • Loading branch information
pcgod committed Dec 24, 2009
1 parent a6a4bba commit b39f73b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/mumble/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down
16 changes: 8 additions & 8 deletions src/mumble/UserModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -1165,7 +1165,7 @@ void UserModel::userTalkingChanged() {

void UserModel::userMuteDeafChanged() {
ClientUser *p=static_cast<ClientUser *>(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();
Expand Down
90 changes: 54 additions & 36 deletions src/mumble/UserView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QVariant> 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<QVariant> 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<QIcon>(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<QVariant> ql = data.toList();
int offset = 0;
offset = ql.size() * 18;
offset = option.rect.topRight().x() - offset;

painter->save();
for (int i=0;i<ql.size();i++) {
QRect r = option.rect;
r.setSize(QSize(16,16));
r.translate(i*18+1,1);
QPixmap pixmap= (qvariant_cast<QIcon>(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) {
Expand Down Expand Up @@ -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<UserModel *>(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;
Expand Down
3 changes: 2 additions & 1 deletion src/mumble/UserView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b39f73b

Please sign in to comment.