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();
273 //if (painter->fontMetrics().width(text) > textRect.width() && !text.contains(QLatin1Char('\n')))
278 void ExpandingDelegate::drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QPixmap& pixmap) const {
283 void ExpandingDelegate::drawBackground ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
288 QStyle *style = model()->treeView()->style() ? model()->treeView()->style() : QApplication::style();
299 bool ExpandingDelegate::editorEvent ( QEvent * event, QAbstractItemModel * /*model*/, const QStyleOptionViewItem & /*option*/, const QModelIndex & index )
315 QList<QTextLayout::FormatRange> ExpandingDelegate::highlightingFromVariantList(const QList<QVariant>& customHighlights) const
320 if (!customHighlights[i].canConvert(QVariant::Int) || !customHighlights[i+1].canConvert(QVariant::Int) || !customHighlights[i+2].canConvert<QTextFormat>()) {
void clear()
virtual void adjustStyle(const QModelIndex &index, QStyleOptionViewItem &option) const
Definition: expandingdelegate.cpp:140
void setHeight(int height)
void setUnderlineStyle(UnderlineStyle style)
Type type() const
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: expandingdelegate.cpp:73
qreal height() const
int length() const
virtual QTreeView * treeView() const =0
virtual void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QPixmap &pixmap) const
QStyle * style() const
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
void setBlue(int blue)
virtual void heightChanged() const
Definition: expandingdelegate.cpp:296
Qt::Alignment alignment() const
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setRed(int red)
virtual void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QPixmap &pixmap) const
Definition: expandingdelegate.cpp:278
void update()
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Definition: expandingdelegate.cpp:299
T value(int i) const
void setLineWidth(qreal width)
const QColor & color() const
void setForeground(const QBrush &brush)
size
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
void setWrapMode(WrapMode mode)
int count(const T &value) const
void append(const T &value)
virtual QList< QTextLayout::FormatRange > createHighlighting(const QModelIndex &index, QStyleOptionViewItem &option) const
Definition: expandingdelegate.cpp:115
void adjustRect(QRect &rect) const
Definition: expandingdelegate.cpp:146
int red() const
int left() const
QWidget * expandingWidget(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:431
void setBackground(const QBrush &brush)
QPaintDevice * device() const
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
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
QModelIndex parent() const
QPalette palette()
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:315
int green() const
Qt::Alignment m_cachedAlignment
Definition: expandingdelegate.h:85
void setFontWeight(int weight)
void setRight(int x)
int blue() const
const QBrush & base() const
int width() const
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
QVariant data(int role) const
QStyle * style()
virtual void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const =0
virtual int columnCount(const QModelIndex &parent) const =0
virtual void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: expandingdelegate.cpp:283
int height() const
int bottom() const
QPoint topLeft() const
int column() const
int length() const
static QColor getUsedBackgroundColor(const QStyleOptionViewItem &option, const QModelIndex &index)
Definition: expandingdelegate.cpp:41
QList< QTextLayout::FormatRange > m_cachedHighlights
Definition: expandingdelegate.h:83
void setUnderlineColor(const QColor &color)
void setColor(const QColor &color)
void setAlignment(QFlags< Qt::AlignmentFlag > alignment)
void setLeft(int x)
bool isValid() const
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-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.