~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to vcs/cvsservice/annotateview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 by Robert Gruber                                   *
3
 
 *   rgruber@users.sourceforge.net                                         *
4
 
 *                                                                         *
5
 
 *   This file has been taken from cervisia an adapted to fit my needs:    *
6
 
 *   Copyright (C) 1999-2002 Bernd Gehrmann <bernd@mail.berlios.de>        *
7
 
 *   Copyright (c) 2003-2005 André Wöbbeking <Woebbeking@web.de>           *
8
 
 *                                                                         *
9
 
 *   This program is free software; you can redistribute it and/or modify  *
10
 
 *   it under the terms of the GNU General Public License as published by  *
11
 
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 
 *   (at your option) any later version.                                   *
13
 
 *                                                                         *
14
 
 ***************************************************************************/
15
 
 
16
 
#include "annotateview.h"
17
 
 
18
 
#include <qheader.h>
19
 
#include <qdatetime.h>
20
 
#include <qpainter.h>
21
 
#include <kglobalsettings.h>
22
 
#include <kglobal.h>
23
 
#include <klocale.h>
24
 
#include <kdebug.h>
25
 
 
26
 
#include "annotatepage.h"
27
 
 
28
 
class AnnotateViewItem : public QListViewItem
29
 
{
30
 
    friend class AnnotateView;
31
 
 
32
 
public:
33
 
    enum { LineNumberColumn, AuthorColumn, DateColumn,ContentColumn };
34
 
 
35
 
    AnnotateViewItem(AnnotateView *parent, QString rev, QString author, 
36
 
            QDateTime date, QString content, QString comment, 
37
 
            bool odd, int linenumber);
38
 
 
39
 
    virtual int compare(QListViewItem *item, int col, bool ascending) const;
40
 
    virtual int width(const QFontMetrics &, const QListView *, int col) const;
41
 
    virtual QString text(int col) const;
42
 
    virtual void paintCell(QPainter *, const QColorGroup &, int, int, int);
43
 
 
44
 
private:
45
 
    QString m_revision;
46
 
    QString m_author;
47
 
    QString m_content;
48
 
    QString m_comment;
49
 
    QDateTime m_logDate;
50
 
    bool m_odd;
51
 
    int m_lineNumber;
52
 
 
53
 
    static const int BORDER;
54
 
};
55
 
 
56
 
 
57
 
const int AnnotateViewItem::BORDER = 4;
58
 
 
59
 
 
60
 
AnnotateViewItem::AnnotateViewItem(AnnotateView *parent, QString rev, 
61
 
    QString author, QDateTime date, QString content, QString comment, 
62
 
    bool odd, int linenumber)
63
 
    : QListViewItem(parent)
64
 
    , m_revision(rev)
65
 
    , m_author(author)
66
 
    , m_content(content)
67
 
    , m_comment(comment)
68
 
    , m_logDate(date)
69
 
    , m_odd(odd)
70
 
    , m_lineNumber(linenumber)
71
 
{}
72
 
 
73
 
 
74
 
int AnnotateViewItem::compare(QListViewItem *item, int, bool) const
75
 
{
76
 
    int linenum1 = m_lineNumber;
77
 
    int linenum2 = static_cast<AnnotateViewItem*>(item)->m_lineNumber;
78
 
 
79
 
    return (linenum2 > linenum1)? -1 : (linenum2 < linenum1)? 1 : 0;
80
 
}
81
 
 
82
 
 
83
 
QString AnnotateViewItem::text(int col) const
84
 
{
85
 
    switch (col)
86
 
    {
87
 
    case LineNumberColumn:
88
 
        return QString::number(m_lineNumber);
89
 
    case AuthorColumn:
90
 
        return (m_revision + QChar(' ') + m_author);
91
 
    case DateColumn:
92
 
        return KGlobal::locale()->formatDate(m_logDate.date(), true);
93
 
    case ContentColumn:
94
 
        return m_content;
95
 
    default:
96
 
        ;
97
 
    };
98
 
 
99
 
    return QString::null;
100
 
}
101
 
 
102
 
 
103
 
void AnnotateViewItem::paintCell(QPainter *p, const QColorGroup &, int col, int width, int align)
104
 
{
105
 
    QColor backgroundColor;
106
 
 
107
 
    switch (col)
108
 
    {
109
 
    case LineNumberColumn:
110
 
        backgroundColor = KGlobalSettings::highlightColor();
111
 
        p->setPen(KGlobalSettings::highlightedTextColor());
112
 
        break;
113
 
    default:
114
 
        backgroundColor = m_odd ? KGlobalSettings::baseColor()
115
 
                                : KGlobalSettings::alternateBackgroundColor();
116
 
        p->setPen(KGlobalSettings::textColor());
117
 
        break;
118
 
    };
119
 
 
120
 
    p->fillRect(0, 0, width, height(), backgroundColor);
121
 
 
122
 
    QString str = text(col);
123
 
    if (str.isEmpty())
124
 
        return;
125
 
 
126
 
    if (align & (AlignTop || AlignBottom) == 0)
127
 
            align |= AlignVCenter;
128
 
 
129
 
    p->drawText(BORDER, 0, width - 2*BORDER, height(), align, str);
130
 
}
131
 
 
132
 
 
133
 
int AnnotateViewItem::width(const QFontMetrics &fm, const QListView *, int col) const
134
 
{
135
 
    return fm.width(text(col)) + 2*BORDER;
136
 
}
137
 
 
138
 
 
139
 
/******************************************************************************/
140
 
/*****************Definition of class AnnotateView ****************************/
141
 
/******************************************************************************/
142
 
 
143
 
AnnotateView::AnnotateView(AnnotatePage *parent, const char *name)
144
 
    : KListView(parent, name), QToolTip( viewport() ), 
145
 
    m_page(parent)
146
 
{
147
 
    setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
148
 
    setAllColumnsShowFocus(true);
149
 
    setShowToolTips(false);
150
 
    header()->hide();
151
 
 
152
 
    addColumn(QString::null);
153
 
    addColumn(QString::null);
154
 
    addColumn(QString::null);
155
 
    addColumn(QString::null);
156
 
 
157
 
    setSorting(AnnotateViewItem::LineNumberColumn);
158
 
    setColumnAlignment(AnnotateViewItem::LineNumberColumn, Qt::AlignRight);
159
 
 
160
 
    connect( this, SIGNAL(executed(QListViewItem*)),
161
 
             this, SLOT(itemClicked(QListViewItem*)) );
162
 
}
163
 
 
164
 
 
165
 
void AnnotateView::addLine(QString rev, QString author, QDateTime date, 
166
 
        QString content, QString comment, bool odd)
167
 
{
168
 
    new AnnotateViewItem(this, rev, author, date, content, comment, 
169
 
            odd, childCount()+1);
170
 
}
171
 
 
172
 
 
173
 
QSize AnnotateView::sizeHint() const
174
 
{
175
 
    QFontMetrics fm(fontMetrics());
176
 
    return QSize(100 * fm.width("0"), 20 * fm.lineSpacing());
177
 
}
178
 
 
179
 
 
180
 
void AnnotateView::maybeTip( const QPoint & p )
181
 
{
182
 
    AnnotateViewItem * item = dynamic_cast<AnnotateViewItem*>( itemAt( p ) );
183
 
    if (!item)
184
 
        return;
185
 
 
186
 
    const int column(header()->sectionAt(p.x()));
187
 
    if (column != AnnotateViewItem::AuthorColumn &&
188
 
        column != AnnotateViewItem::DateColumn) {
189
 
        return;
190
 
    }
191
 
 
192
 
    QRect r = itemRect( item );
193
 
    //get the dimension of the author + the date column
194
 
    QRect headerRect = header()->sectionRect(AnnotateViewItem::AuthorColumn);
195
 
    headerRect = headerRect.unite(header()->sectionRect(AnnotateViewItem::DateColumn));
196
 
 
197
 
    r.setLeft(headerRect.left());
198
 
    r.setWidth(headerRect.width());
199
 
 
200
 
    if (r.isValid())
201
 
    {
202
 
        tip( r, "<nobr><b>"+item->text(AnnotateViewItem::AuthorColumn)+"</b></nobr><br>"
203
 
                "<nobr>"+item->text(AnnotateViewItem::DateColumn)+"</nobr>"
204
 
                "<pre>"+item->m_comment+"</pre>");
205
 
    }
206
 
}
207
 
 
208
 
void AnnotateView::itemClicked(QListViewItem *item)
209
 
{
210
 
    kdDebug(9006) << "itemClicked()" << endl;
211
 
 
212
 
    AnnotateViewItem * line = dynamic_cast<AnnotateViewItem*>(item);
213
 
    if (line) {
214
 
        kdDebug(9006) << "requesting annotate for revision " << line->m_revision << endl;
215
 
        emit m_page->requestAnnotate(line->m_revision);
216
 
    } else {
217
 
        kdDebug(9006) << "This is not an AnnotateViewItem" << endl;
218
 
    }
219
 
}
220
 
 
221
 
#include "annotateview.moc"