diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:34:13 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:34:13 (GMT) |
commit | 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch) | |
tree | 1dbf50b3dff8d5ca7e9344733968c72704eb15ff /tools/designer/src/lib/shared/sheet_delegate.cpp | |
download | Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2 |
Long live Qt!
Diffstat (limited to 'tools/designer/src/lib/shared/sheet_delegate.cpp')
-rw-r--r-- | tools/designer/src/lib/shared/sheet_delegate.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tools/designer/src/lib/shared/sheet_delegate.cpp b/tools/designer/src/lib/shared/sheet_delegate.cpp new file mode 100644 index 0000000..c0722bb --- /dev/null +++ b/tools/designer/src/lib/shared/sheet_delegate.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sheet_delegate_p.h" + +#include <QtCore/QAbstractItemModel> +#include <QtGui/QTreeView> +#include <QtGui/QStyle> +#include <QtGui/QPainter> + +QT_BEGIN_NAMESPACE + +namespace qdesigner_internal { + +SheetDelegate::SheetDelegate(QTreeView *view, QWidget *parent) + : QItemDelegate(parent), + m_view(view) +{ +} + +void SheetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + const QAbstractItemModel *model = index.model(); + Q_ASSERT(model); + + if (!model->parent(index).isValid()) { + // this is a top-level item. + QStyleOptionButton buttonOption; + + buttonOption.state = option.state; +#ifdef Q_WS_MAC + buttonOption.state |= QStyle::State_Raised; +#endif + buttonOption.state &= ~QStyle::State_HasFocus; + + buttonOption.rect = option.rect; + buttonOption.palette = option.palette; + buttonOption.features = QStyleOptionButton::None; + m_view->style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter, m_view); + + QStyleOption branchOption; + static const int i = 9; // ### hardcoded in qcommonstyle.cpp + QRect r = option.rect; + branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i); + branchOption.palette = option.palette; + branchOption.state = QStyle::State_Children; + + if (m_view->isExpanded(index)) + branchOption.state |= QStyle::State_Open; + + m_view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, m_view); + + // draw text + QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height()); + QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, + model->data(index, Qt::DisplayRole).toString()); + m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter, + option.palette, m_view->isEnabled(), text); + + } else { + QItemDelegate::paint(painter, option, index); + } +} + +QSize SheetDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const +{ + QStyleOptionViewItem option = opt; + QSize sz = QItemDelegate::sizeHint(opt, index) + QSize(2, 2); + return sz; +} + +} // namespace qdesigner_internal + +QT_END_NAMESPACE |