1
/***************************************************************************
2
* Copyright (C) 2013 Savoir-Faire Linux *
3
* @author: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Library General Public *
7
* License version 2 as published by the Free Software Foundation. *
9
* This library is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12
* Library General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
16
**************************************************************************/
17
#include "contactview.h"
19
#include <QtGui/QPainter>
20
#include <QtGui/QPaintEvent>
22
#include <lib/contactproxymodel.h>
23
#include <lib/abstractcontactbackend.h>
25
ContactView::ContactView(QWidget* parent) : CategorizedTreeView(parent)
30
QRect ContactView::phoneRect(const QModelIndex& index) const
32
QRect origin = CategorizedTreeView::visualRect(index);
33
const QRect parentRect = visualRect(index.parent());
34
origin.setX(4 + 48 + parentRect.x() + 4);
35
origin.setWidth(parentRect.width()-48-4);
39
QRect ContactView::visualRect(const QModelIndex& index) const
41
//Detect if it is a phone number
42
if (index.parent().parent().isValid()) {
43
return phoneRect(index);
45
return CategorizedTreeView::visualRect(index);
48
bool ContactView::viewportEvent( QEvent * event ) {
49
#pragma GCC diagnostic push
50
#pragma GCC diagnostic ignored "-Wswitch-enum"
51
switch (event->type()) {
52
case QEvent::HoverEnter:
53
case QEvent::HoverLeave:
54
case QEvent::HoverMove: {
55
const QHoverEvent* he = static_cast<QHoverEvent*>(event);
56
const QModelIndex oldIdx = indexAt(he->oldPos());
57
const QModelIndex newIdx = indexAt(he->pos());
60
const QDropEvent* de = static_cast<QDropEvent*>(event);
61
const QModelIndex newIdx = indexAt(de->pos());
66
//HACK For some reasons, the proxy model fail to forward a valid index to dropMimeData()
68
model()->dropMimeData(de->mimeData(), Qt::TargetMoveAction, newIdx.row(), newIdx.column(), newIdx.parent());
74
#pragma GCC diagnostic pop
75
return CategorizedTreeView::viewportEvent(event);