blob: 36230aee637c53631f810d9b317723c32ee0207a [file] [log] [blame]
Nicolas Jager97a21b42015-12-03 16:55:45 -05001/***************************************************************************
Nicolas Jager540a5112016-01-15 15:54:34 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Nicolas Jager97a21b42015-12-03 16:55:45 -05003 * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include <QStyledItemDelegate>
20#include <qevent.h>
21#include <QTreeWidgetItem>
Nicolas Jager540a5112016-01-15 15:54:34 -050022#include <QScrollBar>
Nicolas Jager97a21b42015-12-03 16:55:45 -050023
24#include "smartlistdelegate.h"
25#include "combar.h"
Nicolas Jager97a21b42015-12-03 16:55:45 -050026#include "smartlist.h"
27
28SmartList::SmartList(QWidget *parent) :
29 QTreeView(parent),
Nicolas Jager540a5112016-01-15 15:54:34 -050030 comBar_(new ComBar(this))
Nicolas Jager97a21b42015-12-03 16:55:45 -050031{
Nicolas Jager540a5112016-01-15 15:54:34 -050032 verticalScrollBar()->hide();
Nicolas Jager97a21b42015-12-03 16:55:45 -050033}
34
35SmartList::~SmartList()
36{
37 delete comBar_;
38}
39
40void
41SmartList::enterEvent(QEvent* event)
42{
43 Q_UNUSED(event);
Nicolas Jager540a5112016-01-15 15:54:34 -050044 verticalScrollBar()->show();
Nicolas Jager97a21b42015-12-03 16:55:45 -050045
46 repaint(0, 0, width(), height());
47}
48
49void
50SmartList::leaveEvent(QEvent* event)
51{
52 Q_UNUSED(event);
53
54 smartListDelegate_->setRowHighlighted(-1);
55
56 currentRow_ = -1;
57
58 if (smartListDelegate_)
59 smartListDelegate_->setRowHighlighted(currentRow_);
60
Nicolas Jager540a5112016-01-15 15:54:34 -050061 verticalScrollBar()->hide();
Nicolas Jager97a21b42015-12-03 16:55:45 -050062
63 comBar_->hide();
64}
65
66void
67SmartList::wheelEvent(QWheelEvent* event)
68{
69 currentRow_ = -1;
70
71 comBar_->hide();
72
73 smartListDelegate_->setRowHighlighted(currentRow_);
74
Nicolas Jager97a21b42015-12-03 16:55:45 -050075 repaint(0, 0, width(), height());
76
77 QTreeView::wheelEvent(event);
78}
79
80void
81SmartList::paintEvent(QPaintEvent* event)
82{
83 QTreeView::paintEvent(event);
84
85 if (currentRow_ > -1)
86 comBar_->show();
87 else
88 comBar_->hide();
89}
90
91void
92SmartList::mouseMoveEvent(QMouseEvent* event)
93{
94 QModelIndex index = indexAt(event->pos());
95
Nicolas Jager97a21b42015-12-03 16:55:45 -050096 repaint(0, 0, width(), height());
97
98 currentRow_ = index.row();
99
100 if (smartListDelegate_)
101 {
102 smartListDelegate_->setRowHighlighted(currentRow_);
103
104 if (currentRow_ > -1)
105 comBar_->show();
106 else
107 comBar_->hide();
108 }
109 QTreeView::mouseMoveEvent(event);
110}
111
112void
113SmartList::setSmartListItemDelegate(SmartListDelegate* delegate)
114{
115 if (delegate)
116 {
117 setItemDelegate(delegate);
118 smartListDelegate_ = delegate;
119 connect(smartListDelegate_ , &SmartListDelegate::rowSelected , comBar_, &ComBar::moveToRow);
120 }
121}