File indexing completed on 2024-05-12 04:57:57

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "bookmarksitemdelegate.h"
0019 #include "bookmarkstreeview.h"
0020 #include "bookmarksmodel.h"
0021 #include "bookmarkitem.h"
0022 
0023 #include <QStyleOption>
0024 #include <QApplication>
0025 #include <QStyle>
0026 
0027 BookmarksItemDelegate::BookmarksItemDelegate(QTreeView* parent)
0028     : QStyledItemDelegate(parent)
0029     , m_tree(parent)
0030 {
0031     Q_ASSERT(m_tree);
0032 }
0033 
0034 void BookmarksItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
0035 {
0036     QStyledItemDelegate::paint(painter, option, index);
0037 
0038     if (index.data(BookmarksModel::TypeRole).toInt() == BookmarkItem::Separator) {
0039         QStyleOption opt = option;
0040         opt.state &= ~QStyle::State_Horizontal;
0041 
0042         // We need to fake continuous line over 2 columns
0043         if (m_tree->model()->columnCount(index) == 2) {
0044             if (index.column() == 1) {
0045                 opt.rect = m_lastRect;
0046             }
0047             else {
0048                 opt.rect.setWidth(opt.rect.width() + m_tree->columnWidth(1));
0049                 m_lastRect = opt.rect;
0050             }
0051         }
0052 
0053         QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, painter);
0054     }
0055 }