summaryrefslogtreecommitdiffstats
path: root/kbugbuster/gui/buglvi.cpp
blob: 1c63b04d958a43f2182cc0bfbcbee257385b1627 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
    buglvi.cpp  -  Custom TQListViewItem that holds a Bug object

    copyright   : (c) 2001 by Martijn Klingens
    email       : klingens@kde.org

    *************************************************************************
    *                                                                       *
    * 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.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <tqfont.h>
#include <tqpainter.h>

#include <kstringhandler.h>
#include <kdebug.h>

#include "bugsystem.h"
#include "bugserver.h"

#include "buglvi.h"

using namespace KBugBusterMainWindow;

BugLVI::BugLVI( TDEListView *parent , const Bug &bug )
: TDEListViewItem( parent, bug.number() + "  ",
                 i18n( "1 day", "%n days", bug.age() ),
                 bug.title(), //KStringHandler::csqueeze( bug.title(), 70 ),
                 Bug::statusLabel( bug.status() ),
                 Bug::severityLabel( bug.severity() ),
                 bug.submitter().fullName() )
{
    m_bug = bug;

    bool hasCommands = BugSystem::self()->server()->hasCommandsFor( bug );
    mCommandState = hasCommands ? BugCommand::Queued : BugCommand::None;

    if ( bug.age() == 0xFFFFFFFF )
        setText( 1, i18n( "Unknown" ) );

    Person developer = bug.developerTODO();
    if ( !developer.name.isEmpty() )
        setText( 3, i18n( "%1 (%2)" ).arg( Bug::statusLabel( bug.status() ), developer.name ) );
}

BugLVI::~BugLVI()
{
}

TQString BugLVI::key( int column, bool /* ascending */ ) const
{
    TQString key;

    if ( column == 0 )
    {
        key = text( 0 ).rightJustify( 10, '0' );
    }
    else if ( column == 1 )
    {
        if ( m_bug.age() == 0xFFFFFFFF )
            key = "0";
        else
            key = TQString::number( m_bug.age() ).rightJustify( 10, '0' );
    }
    else if ( column == 4 )
    {
        key = TQString::number( 10 - m_bug.severity() );
        key += m_bug.number().rightJustify( 10, '0' );
    }
    else
    {
        key = text( column );
    }

    return key;
}

void BugLVI::paintCell(TQPainter* p, const TQColorGroup& cg,
                       int column, int width, int align)
{
    TQColorGroup newCg = cg;
    if ( mCommandState == BugCommand::Queued ) {
        TQFont font = p->font();
        font.setBold( true );
        p->setFont( font );
    } else if ( mCommandState == BugCommand::Sent ) {
        TQFont font = p->font();
        font.setItalic( true );
        p->setFont( font );
    } else if ( m_bug.status() == Bug::Closed ) {
        // Different color for closed bugs
        newCg.setColor( TQColorGroup::Text, cg.color( TQColorGroup::Dark ) );
    }

    TDEListViewItem::paintCell( p, newCg, column, width, align );
}

void BugLVI::setCommandState( BugCommand::State state)
{
    mCommandState = state;
}