[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [zanshin] src/widgets: Don't change the height of the current item
From:       Kevin Ottens <ervin () kde ! org>
Date:       2016-12-06 7:30:29
Message-ID: E1cEACr-0007XH-At () code ! kde ! org
[Download RAW message or body]

Git commit 850dc96ac3d4ed342f17bb649fb22b7288bee313 by Kevin Ottens.
Committed on 06/12/2016 at 07:30.
Pushed by ervin into branch 'master'.

Don't change the height of the current item

Summary:
David convinced me, so making a partial revert of the previous item
delegate changes. We don't change the height of the currently selected
item to display extra text anymore. We keep displaying the date though.

Reviewers: #zanshin, dfaure

Differential Revision: https://phabricator.kde.org/D3599

M  +1    -63   src/widgets/itemdelegate.cpp
M  +0    -8    src/widgets/itemdelegate.h
M  +0    -4    src/widgets/pageview.cpp

https://commits.kde.org/zanshin/850dc96ac3d4ed342f17bb649fb22b7288bee313

diff --git a/src/widgets/itemdelegate.cpp b/src/widgets/itemdelegate.cpp
index 54100e0d..55b0c16f 100644
--- a/src/widgets/itemdelegate.cpp
+++ b/src/widgets/itemdelegate.cpp
@@ -34,26 +34,11 @@
 
 using namespace Widgets;
 
-namespace {
-    const int SELECTED_FACTOR = 3;
-}
-
 ItemDelegate::ItemDelegate(QObject *parent)
     : QStyledItemDelegate(parent)
 {
 }
 
-void ItemDelegate::setCurrentIndex(const QModelIndex &current)
-{
-    if (m_currentIndex.isValid())
-        emit sizeHintChanged(m_currentIndex);
-
-    m_currentIndex = current;
-
-    if (m_currentIndex.isValid())
-        emit sizeHintChanged(m_currentIndex);
-}
-
 QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option,
                              const QModelIndex &index) const
 {
@@ -62,10 +47,7 @@ QSize ItemDelegate::sizeHint(const QStyleOptionViewItem \
&option,  initStyleOption(&opt, index);
     opt.features = QStyleOptionViewItemV4::HasCheckIndicator;
     opt.text += ' ' + QLocale().dateFormat(QLocale::ShortFormat).toUpper() \
                + ' ';
-    QSize res = QStyledItemDelegate::sizeHint(opt, index);
-    if (m_currentIndex == index)
-        res.setHeight(res.height() * SELECTED_FACTOR);
-    return res;
+    return QStyledItemDelegate::sizeHint(opt, index);
 }
 
 void ItemDelegate::paint(QPainter *painter,
@@ -93,7 +75,6 @@ void ItemDelegate::paint(QPainter *painter,
     const auto isDone = task ? task->isDone() : false;
     const auto isEnabled = (opt.state & QStyle::State_Enabled);
     const auto isActive = (opt.state & QStyle::State_Active);
-    const auto isCurrent = (m_currentIndex == index);
     const auto isSelected = (opt.state & QStyle::State_Selected);
     const auto isEditing = (opt.state & QStyle::State_Editing);
 
@@ -133,17 +114,11 @@ void ItemDelegate::paint(QPainter *painter,
     const auto dueDateWidth = dueDate.isValid() ? \
(summaryMetrics.width(dueDateText) + 2 * textMargin) : 0;  
 
-    if (isCurrent)
-        opt.rect.setHeight(opt.rect.height() / SELECTED_FACTOR);
-
     const auto checkRect = \
                style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, \
                &opt, widget);
     const auto summaryRect = \
                style->subElementRect(QStyle::SE_ItemViewItemText, &opt, \
                widget)
                              .adjusted(textMargin, 0, -dueDateWidth - \
                textMargin, 0);
     const auto dueDateRect = opt.rect.adjusted(opt.rect.width() - \
dueDateWidth, 0, 0, 0);  
-    if (isCurrent)
-        opt.rect.setHeight(opt.rect.height() * SELECTED_FACTOR);
-
 
     // Draw background
     style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, \
widget); @@ -169,41 +144,4 @@ void ItemDelegate::paint(QPainter *painter,
     if (!dueDateText.isEmpty()) {
         painter->drawText(dueDateRect, Qt::AlignCenter, dueDateText);
     }
-
-    // Draw the extra text
-    const auto extraText = [artifact] {
-        auto text = artifact ? artifact->text() : QString();
-        while (text.startsWith('\n'))
-            text.remove(0, 1);
-        return text;
-    }();
-
-    if (isCurrent && !extraText.isEmpty()) {
-        const auto extraTextRect = opt.rect.adjusted(summaryRect.left(),
-                                                     opt.rect.height() / \
                SELECTED_FACTOR,
-                                                     0, 0);
-
-        auto gradient = QLinearGradient(extraTextRect.topLeft(), \
                extraTextRect.bottomLeft());
-        gradient.setColorAt(0.0, baseColor);
-        gradient.setColorAt(0.75, baseColor);
-        gradient.setColorAt(1.0, Qt::transparent);
-
-        painter->setPen(QPen(QBrush(gradient), 0.0));
-        painter->setFont(baseFont);
-        painter->drawText(extraTextRect, Qt::AlignTop | Qt::TextWordWrap, \
                extraText);
-    }
-}
-
-void ItemDelegate::updateEditorGeometry(QWidget *editor, const \
                QStyleOptionViewItem &option, const QModelIndex &index) \
                const
-{
-    QStyleOptionViewItemV4 opt = option;
-    initStyleOption(&opt, index);
-
-    const QWidget *widget = opt.widget;
-    QStyle *style = widget ? widget->style() : QApplication::style();
-
-    if (m_currentIndex == index)
-        opt.rect.setHeight(option.rect.height() / SELECTED_FACTOR);
-    const auto textRect = \
                style->subElementRect(QStyle::SE_ItemViewItemText, &opt, \
                widget);
-    editor->setGeometry(textRect);
 }
diff --git a/src/widgets/itemdelegate.h b/src/widgets/itemdelegate.h
index baabd314..c0eda2c6 100644
--- a/src/widgets/itemdelegate.h
+++ b/src/widgets/itemdelegate.h
@@ -35,19 +35,11 @@ class ItemDelegate : public QStyledItemDelegate
 public:
     explicit ItemDelegate(QObject *parent = Q_NULLPTR);
 
-    void setCurrentIndex(const QModelIndex &current);
-
     QSize sizeHint(const QStyleOptionViewItem &option,
                    const QModelIndex &index) const Q_DECL_OVERRIDE;
     void paint(QPainter *painter,
                const QStyleOptionViewItem &option,
                const QModelIndex &index) const Q_DECL_OVERRIDE;
-    void updateEditorGeometry(QWidget *editor,
-                              const QStyleOptionViewItem &option,
-                              const QModelIndex &index) const \
                Q_DECL_OVERRIDE;
-
-private:
-    QPersistentModelIndex m_currentIndex;
 };
 
 }
diff --git a/src/widgets/pageview.cpp b/src/widgets/pageview.cpp
index 0cf6f895..34ee513e 100644
--- a/src/widgets/pageview.cpp
+++ b/src/widgets/pageview.cpp
@@ -367,10 +367,6 @@ void PageView::onFilterToggled(bool show)
 
 void PageView::onCurrentChanged(const QModelIndex &current)
 {
-    auto delegate = \
                qobject_cast<ItemDelegate*>(m_centralView->itemDelegate());
-    if (delegate)
-        delegate->setCurrentIndex(current);
-
     auto data = current.data(Presentation::QueryTreeModelBase::ObjectRole);
  if (!data.isValid())
         return;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic