<commit_before>/*
  This file is part of KOrganizer.

  Copyright (c) 2008 <NAME> <<EMAIL>>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/

#include "kotododelegates.h"

#include "koprefs.h"

#include "kcheckcombobox.h"
#include "kotodomodel.h"
#include "kotodoviewview.h"

#include <libkdepim/kdateedit.h>
#include <libkdepim/categoryhierarchyreader.h>

#include <kcal/calendar.h>
#include <kcal/calfilter.h>

#include <kcolorscheme.h>
#include <kcombobox.h>
#include <kdebug.h>

#include <QApplication>
#include <QSlider>
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QColor>
#include <QStyle>
#include <QStyleOptionViewItem>
#include <QStyleOptionProgressBar>
#include <QSize>
#include <QPoint>
#include <QEvent>
#include <QPaintEvent>
#include <QTextDocument>
#include <QFont>
#include <QFontMetrics>
#include <QToolTip>

using namespace KCal;
using namespace KPIM;

// ---------------- COMPLETION DELEGATE --------------------------
// ---------------------------------------------------------------

KOTodoCompleteDelegate::KOTodoCompleteDelegate( QObject *parent )
 : QStyledItemDelegate( parent )
{
}

KOTodoCompleteDelegate::~KOTodoCompleteDelegate()
{
}

void KOTodoCompleteDelegate::paint( QPainter *painter,
                                    const QStyleOptionViewItem &option,
                                    const QModelIndex &index ) const
{
  QStyle *style;

  QStyleOptionViewItemV4 opt = option;
  initStyleOption( &opt, index );

  style = opt.widget ? opt.widget->style() : QApplication::style();
  style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter );

#if QT_VERSION >= 0x040600
#ifdef __GNUC__
#warning QTreeView should now set State_Editing correctly, remove the workaround
#endif
#endif
  bool isEditing = false;
  KOTodoViewView *view = qobject_cast<KOTodoViewView*>( parent() );
  if ( view ) {
    isEditing = view->isEditing( index );
  }

  // TODO QTreeView does not set State_Editing. Qt task id 205051
  // should be fixed with Qt 4.5, but wasn't. According to the
  // task tracker the fix arrives in "Some future release".
  if ( !( opt.state & QStyle::State_Editing ) && !isEditing ) {
    QStyleOptionProgressBar pbOption;
    pbOption.QStyleOption::operator=( option );
    initStyleOptionProgressBar( &pbOption, index );

    style->drawControl( QStyle::CE_ProgressBar, &pbOption, painter );
  }
}
<commit_msg>Backport r1081122 by smartins from trunk to the 4.4 branch:<commit_after>/*
  This file is part of KOrganizer.

  Copyright (c) 2008 <NAME> <<EMAIL>>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/

#include "kotododelegates.h"

#include "koprefs.h"

#include "kcheckcombobox.h"
#include "kotodomodel.h"
#include "kotodoviewview.h"

#include <libkdepim/kdateedit.h>
#include <libkdepim/categoryhierarchyreader.h>

#include <kcal/calendar.h>
#include <kcal/calfilter.h>

#include <kcolorscheme.h>
#include <kcombobox.h>
#include <kdebug.h>

#include <QApplication>
#include <QSlider>
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QColor>
#include <QStyle>
#include <QStyleOptionViewItem>
#include <QStyleOptionProgressBar>
#include <QSize>
#include <QPoint>
#include <QEvent>
#include <QPaintEvent>
#include <QTextDocument>
#include <QFont>
#include <QFontMetrics>
#include <QToolTip>

using namespace KCal;
using namespace KPIM;

// ---------------- COMPLETION DELEGATE --------------------------
// ---------------------------------------------------------------

KOTodoCompleteDelegate::KOTodoCompleteDelegate( QObject *parent )
 : QStyledItemDelegate( parent )
{
}

KOTodoCompleteDelegate::~KOTodoCompleteDelegate()
{
}

void KOTodoCompleteDelegate::paint( QPainter *painter,
                                    const QStyleOptionViewItem &option,
                                    const QModelIndex &index ) const
{
  QStyle *style;

  QStyleOptionViewItemV4 opt = option;
  initStyleOption( &opt, index );

  style = opt.widget ? opt.widget->style() : QApplication::style();
  style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter );

#if QT_VERSION >= 0x040600
#ifdef __GNUC__
#warning QTreeView should now set State_Editing correctly, remove the workaround
#endif
#endif
  if ( index.data( Qt::EditRole ).toInt() > 0 ) {
    bool isEditing = false;
    KOTodoViewView *view = qobject_cast<KOTodoViewView*>( parent() );
    if ( view ) {
      isEditing = view->isEditing( index );
    }

    // TODO QTreeView does not set State_Editing. Qt task id 205051
    // should be fixed with Qt 4.5, but wasn't. According to the
    // task tracker the fix arrives in "Some future release".
    if ( !( opt.state & QStyle::State_Editing ) && !isEditing ) {
      QStyleOptionProgressBar pbOption;
      pbOption.QStyleOption::operator=( option );
      initStyleOptionProgressBar( &pbOption, index );

      style->drawControl( QStyle::CE_ProgressBar, &pbOption, painter );
    }
  }
}

{'fraction_non_alphanumeric': 0.12224902019897498, 'fraction_numerical': 0.011154657823334338, 'mean_word_length': 3.52901023890785, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2757655', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1960, 'n_words': 674}