Falkon Develop
Cross-platform Qt-based web browser
bookmarksitemdelegate.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2014 David Rosca <nowrep@gmail.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* ============================================================ */
19#include "bookmarkstreeview.h"
20#include "bookmarksmodel.h"
21#include "bookmarkitem.h"
22
23#include <QStyleOption>
24#include <QApplication>
25#include <QStyle>
26
28 : QStyledItemDelegate(parent)
29 , m_tree(parent)
30{
31 Q_ASSERT(m_tree);
32}
33
34void BookmarksItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
35{
36 QStyledItemDelegate::paint(painter, option, index);
37
38 if (index.data(BookmarksModel::TypeRole).toInt() == BookmarkItem::Separator) {
39 QStyleOption opt = option;
40 opt.state &= ~QStyle::State_Horizontal;
41
42 // We need to fake continuous line over 2 columns
43 if (m_tree->model()->columnCount(index) == 2) {
44 if (index.column() == 1) {
45 opt.rect = m_lastRect;
46 }
47 else {
48 opt.rect.setWidth(opt.rect.width() + m_tree->columnWidth(1));
49 m_lastRect = opt.rect;
50 }
51 }
52
53 QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, painter);
54 }
55}
BookmarksItemDelegate(QTreeView *parent=nullptr)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override