[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kate/completion/expandingtree
From: David Nolden <david.nolden.kde () art-master ! de>
Date: 2007-10-30 1:01:50
Message-ID: 1193706110.118051.25639.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 730897 by zwabel:
While moving the keyboard-cursor downwards in the completion-list, and when the item \
should be partially expanded, show that information ABOVE the selected item instead \
of below. This way, the actual text of the selected item does not change its position \
when it is selected, which should be easier on the eyes. Now let's test that's true. \
:)
M +16 -4 expandingdelegate.cpp
M +1 -0 expandingdelegate.h
M +49 -8 expandingwidgetmodel.cpp
M +8 -2 expandingwidgetmodel.h
--- trunk/KDE/kdelibs/kate/completion/expandingtree/expandingdelegate.cpp \
#730896:730897 @@ -42,8 +42,14 @@
model()->placeExpandingWidget(index);
//Make sure the decorations are painted at the top, because the center of expanded \
items will be filled with the embedded widget.
- option.decorationAlignment = Qt::AlignTop;
+ if( model()->isPartiallyExpanded(index) == ExpandingWidgetModel::ExpandUpwards )
+ m_cachedAlignment = Qt::AlignBottom;
+ else
+ m_cachedAlignment = Qt::AlignTop;
+ option.decorationAlignment = m_cachedAlignment;
+ option.displayAlignment = m_cachedAlignment;
+
//kDebug() << "Painting row " << index.row() << ", column " << index.column() << \
", internal " << index.internalPointer() << ", drawselected " << \
option.showDecorationSelected << ", selected " << (option.state & \
QStyle::State_Selected);
m_cachedHighlights.clear();
@@ -146,7 +152,9 @@
layout.setAdditionalFormats(additionalFormats);
QTextOption to;
- to.setAlignment(option.displayAlignment);
+
+ to.setAlignment( m_cachedAlignment );
+
to.setWrapMode(QTextOption::WrapAnywhere);
layout.setTextOption(to);
@@ -155,8 +163,12 @@
line.setLineWidth(rect.width());
layout.endLayout();
- layout.draw(painter, rect.topLeft());
-
+ //We need to do some hand layouting here
+ if( to.alignment() & Qt::AlignBottom)
+ layout.draw(painter, QPoint((qreal)rect.left(), (qreal)rect.bottom() - \
line.height()) ); + else
+ layout.draw(painter, rect.topLeft() );
+
return;
//if (painter->fontMetrics().width(text) > textRect.width() && \
!text.contains(QLatin1Char('\n')))
--- trunk/KDE/kdelibs/kate/completion/expandingtree/expandingdelegate.h \
#730896:730897 @@ -73,6 +73,7 @@
mutable QList<int> m_currentColumnStarts;
mutable QList<QTextLayout::FormatRange> m_cachedHighlights;
+ mutable Qt::Alignment m_cachedAlignment;
private:
ExpandingWidgetModel* m_model;
--- trunk/KDE/kdelibs/kate/completion/expandingtree/expandingwidgetmodel.cpp \
#730896:730897 @@ -108,8 +108,11 @@
m_expandingWidgets.clear();
}
-bool ExpandingWidgetModel::isPartiallyExpanded(const QModelIndex& index) const {
- return m_partiallyExpanded.contains(firstColumn(index));
+ExpandingWidgetModel::ExpansionType ExpandingWidgetModel::isPartiallyExpanded(const \
QModelIndex& index) const { + if( m_partiallyExpanded.contains(firstColumn(index)) )
+ return m_partiallyExpanded[firstColumn(index)];
+ else
+ return NotExpanded;
}
void ExpandingWidgetModel::partiallyUnExpand(const QModelIndex& idx_)
@@ -147,14 +150,39 @@
if( !isExpanded(idx) && variant.type() == QVariant::String) {
//kDebug() << "expanding: " << idx;
- m_partiallyExpanded.insert(idx, true);
+
+ //Either expand upwards or downwards, choose in a way that
+ //the visible fields of the new selected entry are not moved.
+ if( oldIndex.isValid() && (oldIndex < idx || (!(oldIndex < idx) && \
oldIndex.parent() < idx.parent()) ) ) + m_partiallyExpanded.insert(idx, \
ExpandUpwards); + else
+ m_partiallyExpanded.insert(idx, ExpandDownwards);
//Say that one row above until one row below has changed, so no items will \
need to be moved(the space that is taken from one item is given to \
the other)
- if( oldIndex.isValid() && oldIndex < idx )
+ if( oldIndex.isValid() && oldIndex < idx ) {
emit dataChanged(oldIndex, idx);
- else if( oldIndex.isValid() && idx < oldIndex )
+
+ QModelIndex nextLine = idx.sibling(idx.row()+1, idx.column());
+ if( !nextLine.isValid() )
+ nextLine = idx;
+
+ //This is needed to keep the item we are expanding completely visible. \
Qt does not scroll the view to keep the item visible. + //But we must make \
sure that it isn't too expensive. + //We need to make sure that scrolling \
is efficient, and the whole content is not repainted. + //Since we are \
scrolling anyway, we can keep the next line visible, which might be a cool feature. + \
+ //Since this also doesn't work smoothly, leave it for now
+ //treeView()->scrollTo( nextLine, QAbstractItemView::EnsureVisible );
+ } else if( oldIndex.isValid() && idx < oldIndex ) {
emit dataChanged(idx, oldIndex);
- else
+
+ //For consistency with the down-scrolling, we keep one additional line \
visible above the current visible. +
+ //Since this also doesn't work smoothly, leave it for now
+/* QModelIndex prevLine = idx.sibling(idx.row()-1, idx.column());
+ if( prevLine.isValid() )
+ treeView()->scrollTo( prevLine );*/
+ } else
emit dataChanged(idx, idx);
} else if( oldIndex.isValid() ) {
//We are not partially expanding a new row, but we previously had a \
partially expanded row. So signalize that it has been unexpanded. @@ -180,6 +208,11 \
@@ if( !idx.isValid() )
return QRect();
+ ExpansionType expansion = ExpandDownwards;
+
+ if( m_partiallyExpanded.find(idx) != m_partiallyExpanded.end() )
+ expansion = m_partiallyExpanded[idx];
+
//Get the whole rectangle of the row:
QModelIndex rightMostIndex = idx;
QModelIndex tempIndex = idx;
@@ -193,8 +226,16 @@
rect.setRight( rightMostRect.right() - 5 );
//These offsets must match exactly those used in ExpandingDelegate::sizeHint()
- rect.setTop( rect.top() + basicRowHeight(idx) + 5 );
- rect.setBottom( rightMostRect.bottom() - 5 );
+ int top = rect.top() + 5;
+ int bottom = rightMostRect.bottom() - 5 ;
+
+ if( expansion == ExpandDownwards )
+ top += basicRowHeight(idx);
+ else
+ bottom -= basicRowHeight(idx);
+
+ rect.setTop( top );
+ rect.setBottom( bottom );
return rect;
}
--- trunk/KDE/kdelibs/kate/completion/expandingtree/expandingwidgetmodel.h \
#730896:730897 @@ -60,8 +60,14 @@
///@return whether the row given through index is expandable
bool isExpandable(const QModelIndex& index) const;
+ enum ExpansionType {
+ NotExpanded = 0,
+ ExpandDownwards, //The additional(expanded) information is shown UNDER the \
original information + ExpandUpwards //The additional(expanded) information is \
shown ABOVE the original information + };
+
///Returns whether the given index is currently partially expanded. Does not do \
any other checks like calling models for data.
- bool isPartiallyExpanded(const QModelIndex& index) const;
+ ExpansionType isPartiallyExpanded(const QModelIndex& index) const;
///@return whether row is currently expanded
bool isExpanded(const QModelIndex & row) const;
@@ -132,7 +138,7 @@
int basicRowHeight( const QModelIndex& index ) const;
private:
- QMap<QPersistentModelIndex, bool> m_partiallyExpanded;
+ QMap<QPersistentModelIndex, ExpansionType> m_partiallyExpanded;
// Store expanding-widgets and cache whether items can be expanded
mutable QMap<QPersistentModelIndex, ExpandingType> m_expandState;
QMap< QPersistentModelIndex, QPointer<QWidget> > m_expandingWidgets; //Map rows \
to their expanding-widgets
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic