Kate
expandingdelegate.cpp
Go to the documentation of this file.
41 static QColor getUsedBackgroundColor(const QStyleOptionViewItem & option, const QModelIndex& index) {
59 //Reduce the colors that are less visible to the eye, because they are closer to black when it comes to contrast
60 //The most significant color to the eye is green. Then comes red, and then blue, with blue _much_ less significant.
70 return abs(foreground.green()-background.green()) + abs(foreground.red()-background.red()) + abs(foreground.blue() - background.blue());
73 void ExpandingDelegate::paint( QPainter * painter, const QStyleOptionViewItem & optionOld, const QModelIndex & index ) const
84 //Make sure the decorations are painted at the top, because the center of expanded items will be filled with the embedded widget.
93 //kDebug( 13035 ) << "Painting row " << index.row() << ", column " << index.column() << ", internal " << index.internalPointer() << ", drawselected " << option.showDecorationSelected << ", selected " << (option.state & QStyle::State_Selected);
115 QList<QTextLayout::FormatRange> ExpandingDelegate::createHighlighting(const QModelIndex& index, QStyleOptionViewItem& option) const {
125 QSize ExpandingDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
133 s.setHeight( widgetSize.height() + s.height() + 10 ); //10 is the sum that must match exactly the offsets used in ExpandingWidgetModel::placeExpandingWidgets
140 void ExpandingDelegate::adjustStyle( const QModelIndex& index, QStyleOptionViewItem & option ) const
154 rect.setRight(model()->treeView()->columnViewportPosition(columnCount-1) + model()->treeView()->columnWidth(columnCount-1));
158 void ExpandingDelegate::drawDisplay( QPainter * painter, const QStyleOptionViewItem & option, const QRect & _rect, const QString & text ) const
175 if (i != 0 && m_cachedHighlights[i - 1].start + m_cachedHighlights[i - 1].length > m_currentColumnStart) {
178 before.length = m_cachedHighlights[i - 1].start + m_cachedHighlights[i - 1].length - m_currentColumnStart;
192 missingFormats = text.length() - (additionalFormats.back().length + additionalFormats.back().start);
219 // kDebug() << "values:" << invertedContrast << currentContrast << invertedColor.name() << currentColor.name();
222 // kDebug() << text << additionalFormats[a].length << "switching from" << currentColor.name() << "to" << invertedColor.name();
246 // kDebug( 13035 ) << "Highlights for text [" << text << "] col start " << m_currentColumnStart << ":";
248 // kDebug( 13035 ) << fr.start << " len " << fr.length << "foreground" << fr.format.foreground() << "background" << fr.format.background();
272 //if (painter->fontMetrics().width(text) > textRect.width() && !text.contains(QLatin1Char('\n')))
277 void ExpandingDelegate::drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QPixmap& pixmap) const {
282 void ExpandingDelegate::drawBackground ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
287 QStyle *style = model()->treeView()->style() ? model()->treeView()->style() : QApplication::style();
298 bool ExpandingDelegate::editorEvent ( QEvent * event, QAbstractItemModel * /*model*/, const QStyleOptionViewItem & /*option*/, const QModelIndex & index )
314 QList<QTextLayout::FormatRange> ExpandingDelegate::highlightingFromVariantList(const QList<QVariant>& customHighlights) const
319 if (!customHighlights[i].canConvert(QVariant::Int) || !customHighlights[i+1].canConvert(QVariant::Int) || !customHighlights[i+2].canConvert<QTextFormat>()) {
virtual void adjustStyle(const QModelIndex &index, QStyleOptionViewItem &option) const
Definition: expandingdelegate.cpp:140
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: expandingdelegate.cpp:73
virtual QTreeView * treeView() const =0
ExpandingDelegate(ExpandingWidgetModel *model, QObject *parent=0L)
Definition: expandingdelegate.cpp:34
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: expandingdelegate.cpp:125
ExpansionType isPartiallyExpanded(const QModelIndex &index) const
Returns whether the given index is currently partially expanded. Does not do any other checks like ca...
Definition: expandingwidgetmodel.cpp:139
virtual void heightChanged() const
Definition: expandingdelegate.cpp:295
virtual void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QPixmap &pixmap) const
Definition: expandingdelegate.cpp:277
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Definition: expandingdelegate.cpp:298
void placeExpandingWidget(const QModelIndex &row)
Places and shows the expanding-widget for the given row, if it should be visible and is valid...
Definition: expandingwidgetmodel.cpp:370
virtual QList< QTextLayout::FormatRange > createHighlighting(const QModelIndex &index, QStyleOptionViewItem &option) const
Definition: expandingdelegate.cpp:115
void adjustRect(QRect &rect) const
Definition: expandingdelegate.cpp:146
QWidget * expandingWidget(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:431
static double readabilityContrast(QColor foreground, QColor background)
Definition: expandingdelegate.cpp:67
virtual void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
Definition: expandingdelegate.cpp:158
QSize basicSizeHint(const QModelIndex &index) const
Definition: expandingdelegate.cpp:121
QList< QTextLayout::FormatRange > highlightingFromVariantList(const QList< QVariant > &customHighlights) const
Creates a list of FormatRanges as should be returned by createHighlighting from a list of QVariants a...
Definition: expandingdelegate.cpp:314
Qt::Alignment m_cachedAlignment
Definition: expandingdelegate.h:85
void setExpanded(QModelIndex index, bool expanded)
Change the expand-state of the row given through index. The display will be updated.
Definition: expandingwidgetmodel.cpp:311
virtual void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: expandingdelegate.cpp:282
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static QColor getUsedBackgroundColor(const QStyleOptionViewItem &option, const QModelIndex &index)
Definition: expandingdelegate.cpp:41
QList< QTextLayout::FormatRange > m_cachedHighlights
Definition: expandingdelegate.h:83
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.