Changeset View
Changeset View
Standalone View
Standalone View
plugins/quickopen/expandingtree/expandingdelegate.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
73 | void ExpandingDelegate::paint( QPainter * painter, const QStyleOptionViewItem & optionOld, const QModelIndex & index ) const | 73 | void ExpandingDelegate::paint( QPainter * painter, const QStyleOptionViewItem & optionOld, const QModelIndex & index ) const | ||
74 | { | 74 | { | ||
75 | QStyleOptionViewItem option(optionOld); | 75 | QStyleOptionViewItem option(optionOld); | ||
76 | 76 | | |||
77 | m_currentIndex = index; | 77 | m_currentIndex = index; | ||
78 | 78 | | |||
79 | adjustStyle(index, option); | 79 | adjustStyle(index, option); | ||
80 | 80 | | |||
81 | const QModelIndex sourceIndex = model()->mapToSource(index); | ||||
81 | if( index.column() == 0 ) | 82 | if( index.column() == 0 ) | ||
82 | model()->placeExpandingWidget(index); | 83 | model()->placeExpandingWidget(sourceIndex); | ||
83 | 84 | | |||
84 | //Make sure the decorations are painted at the top, because the center of expanded items will be filled with the embedded widget. | 85 | //Make sure the decorations are painted at the top, because the center of expanded items will be filled with the embedded widget. | ||
85 | if( model()->isPartiallyExpanded(index) == ExpandingWidgetModel::ExpandUpwards ) | 86 | if( model()->isPartiallyExpanded(sourceIndex) == ExpandingWidgetModel::ExpandUpwards ) | ||
86 | m_cachedAlignment = Qt::AlignBottom; | 87 | m_cachedAlignment = Qt::AlignBottom; | ||
87 | else | 88 | else | ||
88 | m_cachedAlignment = Qt::AlignTop; | 89 | m_cachedAlignment = Qt::AlignTop; | ||
89 | 90 | | |||
90 | option.decorationAlignment = m_cachedAlignment; | 91 | option.decorationAlignment = m_cachedAlignment; | ||
91 | option.displayAlignment = m_cachedAlignment; | 92 | option.displayAlignment = m_cachedAlignment; | ||
92 | 93 | | |||
93 | //qCDebug( PLUGIN_QUICKOPEN ) << "Painting row " << index.row() << ", column " << index.column() << ", internal " << index.internalPointer() << ", drawselected " << option.showDecorationSelected << ", selected " << (option.state & QStyle::State_Selected); | 94 | //qCDebug( PLUGIN_QUICKOPEN ) << "Painting row " << index.row() << ", column " << index.column() << ", internal " << index.internalPointer() << ", drawselected " << option.showDecorationSelected << ", selected " << (option.state & QStyle::State_Selected); | ||
94 | 95 | | |||
95 | m_cachedHighlights.clear(); | 96 | m_cachedHighlights.clear(); | ||
96 | m_backgroundColor = getUsedBackgroundColor(option, index); | 97 | m_backgroundColor = getUsedBackgroundColor(option, index); | ||
97 | 98 | | |||
98 | if (model()->indexIsItem(index) ) { | 99 | if (model()->indexIsItem(sourceIndex) ) { | ||
99 | m_currentColumnStart = 0; | 100 | m_currentColumnStart = 0; | ||
100 | m_cachedHighlights = createHighlighting(index, option); | 101 | m_cachedHighlights = createHighlighting(index, option); | ||
101 | } | 102 | } | ||
102 | 103 | | |||
103 | /*qCDebug( PLUGIN_QUICKOPEN ) << "Highlights for line:"; | 104 | /*qCDebug( PLUGIN_QUICKOPEN ) << "Highlights for line:"; | ||
104 | foreach (const QTextLayout::FormatRange& fr, m_cachedHighlights) | 105 | foreach (const QTextLayout::FormatRange& fr, m_cachedHighlights) | ||
105 | qCDebug( PLUGIN_QUICKOPEN ) << fr.start << " len " << fr.length << " format ";*/ | 106 | qCDebug( PLUGIN_QUICKOPEN ) << fr.start << " len " << fr.length << " format ";*/ | ||
106 | 107 | | |||
107 | QItemDelegate::paint(painter, option, index); | 108 | QItemDelegate::paint(painter, option, index); | ||
108 | 109 | | |||
109 | ///This is a bug workaround for the Qt raster paint engine: It paints over widgets embedded into the viewport when updating due to mouse events | 110 | ///This is a bug workaround for the Qt raster paint engine: It paints over widgets embedded into the viewport when updating due to mouse events | ||
110 | ///@todo report to Qt Software | 111 | ///@todo report to Qt Software | ||
111 | if( model()->isExpanded(index) && model()->expandingWidget( index ) ) | 112 | if( model()->isExpanded(sourceIndex) && model()->expandingWidget( sourceIndex ) ) | ||
112 | model()->expandingWidget( index )->update(); | 113 | model()->expandingWidget( sourceIndex )->update(); | ||
113 | } | 114 | } | ||
114 | 115 | | |||
115 | QList<QTextLayout::FormatRange> ExpandingDelegate::createHighlighting(const QModelIndex& index, QStyleOptionViewItem& option) const { | 116 | QList<QTextLayout::FormatRange> ExpandingDelegate::createHighlighting(const QModelIndex& index, QStyleOptionViewItem& option) const { | ||
116 | Q_UNUSED( index ); | 117 | Q_UNUSED( index ); | ||
117 | Q_UNUSED( option ); | 118 | Q_UNUSED( option ); | ||
118 | return QList<QTextLayout::FormatRange>(); | 119 | return QList<QTextLayout::FormatRange>(); | ||
119 | } | 120 | } | ||
120 | 121 | | |||
121 | QSize ExpandingDelegate::basicSizeHint( const QModelIndex& index ) const { | 122 | QSize ExpandingDelegate::basicSizeHint( const QModelIndex& index ) const { | ||
122 | return QItemDelegate::sizeHint( QStyleOptionViewItem(), index ); | 123 | return QItemDelegate::sizeHint( QStyleOptionViewItem(), index ); | ||
123 | } | 124 | } | ||
124 | 125 | | |||
125 | QSize ExpandingDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const | 126 | QSize ExpandingDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const | ||
126 | { | 127 | { | ||
128 | const QModelIndex sourceIndex = model()->mapToSource(index); | ||||
127 | QSize s = QItemDelegate::sizeHint( option, index ); | 129 | QSize s = QItemDelegate::sizeHint( option, index ); | ||
128 | if( model()->isExpanded(index) && model()->expandingWidget( index ) ) | 130 | if( model()->isExpanded(sourceIndex) && model()->expandingWidget(sourceIndex) ) | ||
129 | { | 131 | { | ||
130 | QWidget* widget = model()->expandingWidget( index ); | 132 | QWidget* widget = model()->expandingWidget( sourceIndex ); | ||
131 | QSize widgetSize = widget->size(); | 133 | QSize widgetSize = widget->size(); | ||
132 | 134 | | |||
133 | s.setHeight( widgetSize.height() + s.height() + 10 ); //10 is the sum that must match exactly the offsets used in ExpandingWidgetModel::placeExpandingWidgets | 135 | s.setHeight( widgetSize.height() + s.height() + 10 ); //10 is the sum that must match exactly the offsets used in ExpandingWidgetModel::placeExpandingWidgets | ||
134 | } else if( model()->isPartiallyExpanded( index ) != ExpandingWidgetModel::ExpansionType::NotExpanded) { | 136 | } else if( model()->isPartiallyExpanded( sourceIndex ) != ExpandingWidgetModel::ExpansionType::NotExpanded) { | ||
135 | s.setHeight( s.height() + 30 + 10 ); | 137 | s.setHeight( s.height() + 30 + 10 ); | ||
136 | } | 138 | } | ||
137 | return s; | 139 | return s; | ||
138 | } | 140 | } | ||
139 | 141 | | |||
140 | void ExpandingDelegate::adjustStyle( const QModelIndex& index, QStyleOptionViewItem & option ) const | 142 | void ExpandingDelegate::adjustStyle( const QModelIndex& index, QStyleOptionViewItem & option ) const | ||
141 | { | 143 | { | ||
142 | Q_UNUSED(index) | 144 | Q_UNUSED(index) | ||
143 | Q_UNUSED(option) | 145 | Q_UNUSED(option) | ||
144 | } | 146 | } | ||
145 | 147 | | |||
146 | void ExpandingDelegate::adjustRect(QRect& rect) const { | 148 | void ExpandingDelegate::adjustRect(QRect& rect) const | ||
147 | if (!model()->indexIsItem(m_currentIndex) /*&& m_currentIndex.column() == 0*/) { | 149 | { | ||
150 | const QModelIndex sourceIndex = model()->mapToSource(m_currentIndex); | ||||
151 | if (!model()->indexIsItem(sourceIndex) /*&& m_currentIndex.column() == 0*/) { | ||||
148 | 152 | | |||
149 | rect.setLeft(model()->treeView()->columnViewportPosition(0)); | 153 | rect.setLeft(model()->treeView()->columnViewportPosition(0)); | ||
150 | int columnCount = model()->columnCount(m_currentIndex.parent()); | 154 | int columnCount = model()->columnCount(sourceIndex.parent()); | ||
151 | 155 | | |||
152 | if(!columnCount) | 156 | if(!columnCount) | ||
153 | return; | 157 | return; | ||
154 | rect.setRight(model()->treeView()->columnViewportPosition(columnCount-1) + model()->treeView()->columnWidth(columnCount-1)); | 158 | rect.setRight(model()->treeView()->columnViewportPosition(columnCount-1) + model()->treeView()->columnWidth(columnCount-1)); | ||
155 | } | 159 | } | ||
156 | } | 160 | } | ||
157 | 161 | | |||
158 | void ExpandingDelegate::drawDisplay( QPainter * painter, const QStyleOptionViewItem & option, const QRect & _rect, const QString & text ) const | 162 | void ExpandingDelegate::drawDisplay( QPainter * painter, const QStyleOptionViewItem & option, const QRect & _rect, const QString & text ) const | ||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | 262 | #endif | |||
277 | 281 | | |||
278 | return; | 282 | return; | ||
279 | 283 | | |||
280 | //if (painter->fontMetrics().width(text) > textRect.width() && !text.contains(QLatin1Char('\n'))) | 284 | //if (painter->fontMetrics().width(text) > textRect.width() && !text.contains(QLatin1Char('\n'))) | ||
281 | //str = elidedText(option.fontMetrics, textRect.width(), option.textElideMode, text); | 285 | //str = elidedText(option.fontMetrics, textRect.width(), option.textElideMode, text); | ||
282 | //qt_format_text(option.font, textRect, option.displayAlignment, str, 0, 0, 0, 0, painter); | 286 | //qt_format_text(option.font, textRect, option.displayAlignment, str, 0, 0, 0, 0, painter); | ||
283 | } | 287 | } | ||
284 | 288 | | |||
285 | void ExpandingDelegate::drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QPixmap& pixmap) const { | 289 | void ExpandingDelegate::drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QPixmap& pixmap) const | ||
286 | if (model()->indexIsItem(m_currentIndex) ) | 290 | { | ||
291 | const QModelIndex sourceIndex = model()->mapToSource(m_currentIndex); | ||||
292 | if (model()->indexIsItem(sourceIndex)) | ||||
287 | QItemDelegate::drawDecoration(painter, option, rect, pixmap); | 293 | QItemDelegate::drawDecoration(painter, option, rect, pixmap); | ||
288 | } | 294 | } | ||
289 | 295 | | |||
290 | void ExpandingDelegate::drawBackground ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { | 296 | void ExpandingDelegate::drawBackground ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { | ||
291 | Q_UNUSED(index) | 297 | Q_UNUSED(index) | ||
292 | QStyleOptionViewItem opt = option; | 298 | QStyleOptionViewItem opt = option; | ||
293 | //initStyleOption(&opt, index); | 299 | //initStyleOption(&opt, index); | ||
294 | //Problem: This isn't called at all, because drawBrackground is not virtual :-/ | 300 | //Problem: This isn't called at all, because drawBrackground is not virtual :-/ | ||
295 | QStyle *style = model()->treeView()->style() ? model()->treeView()->style() : QApplication::style(); | 301 | QStyle *style = model()->treeView()->style() ? model()->treeView()->style() : QApplication::style(); | ||
296 | style->drawControl(QStyle::CE_ItemViewItem, &opt, painter); | 302 | style->drawControl(QStyle::CE_ItemViewItem, &opt, painter); | ||
297 | } | 303 | } | ||
298 | 304 | | |||
299 | ExpandingWidgetModel* ExpandingDelegate::model() const { | 305 | ExpandingWidgetModel* ExpandingDelegate::model() const { | ||
300 | return m_model; | 306 | return m_model; | ||
301 | } | 307 | } | ||
302 | 308 | | |||
303 | void ExpandingDelegate::heightChanged() const { | 309 | void ExpandingDelegate::heightChanged() const { | ||
304 | } | 310 | } | ||
305 | 311 | | |||
306 | bool ExpandingDelegate::editorEvent ( QEvent * event, QAbstractItemModel * /*model*/, const QStyleOptionViewItem & /*option*/, const QModelIndex & index ) | 312 | bool ExpandingDelegate::editorEvent ( QEvent * event, QAbstractItemModel * /*model*/, const QStyleOptionViewItem & /*option*/, const QModelIndex & index ) | ||
307 | { | 313 | { | ||
308 | if( event->type() == QEvent::MouseButtonRelease ) | 314 | if( event->type() == QEvent::MouseButtonRelease ) | ||
309 | { | 315 | { | ||
316 | const QModelIndex sourceIndex = model()->mapToSource(index); | ||||
310 | event->accept(); | 317 | event->accept(); | ||
311 | model()->setExpanded(index, !model()->isExpanded( index )); | 318 | model()->setExpanded(sourceIndex, !model()->isExpanded(sourceIndex)); | ||
312 | heightChanged(); | 319 | heightChanged(); | ||
313 | 320 | | |||
314 | return true; | 321 | return true; | ||
315 | } else { | 322 | } else { | ||
316 | event->ignore(); | 323 | event->ignore(); | ||
317 | } | 324 | } | ||
318 | 325 | | |||
319 | return false; | 326 | return false; | ||
Show All 25 Lines |