-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_view.cpp
More file actions
132 lines (109 loc) · 3.24 KB
/
log_view.cpp
File metadata and controls
132 lines (109 loc) · 3.24 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "log_view.h"
#include <qheader.h>
#include <qfont.h>
#include <qpen.h>
#include <qcolor.h>
// -------------------------------------------------------
// -------- WGLogView
// -------------------------------------------------------
#define column_margin 0
WGLogView::WGLogView( QWidget* parent, const char* name, WFlags fl ):
QListView( parent, name, fl ),
canFocusLastItem( true )
{
QFont f( font() );
f.setFamily( "Courier" );
setFont( f );
setFrameShape( QFrame::Box );
setFrameShadow( QFrame::Plain );
setLineWidth( 1 );
setHScrollBarMode( QListView::AlwaysOff );
setSorting( -1 );
addColumn( "", 15 );
addColumn( "" );
setRootIsDecorated( false );
setMultiSelection( false );
setSelectionMode( QListView::NoSelection );
setTreeStepSize( 0 );
header()->hide();
disconnect( header(), SIGNAL(sectionClicked(int)), this, SLOT(changeSortColumn(int)) );
connect( verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vertScrollBarValueChanged(int)) );
}
WGLogView::~WGLogView()
{
}
bool WGLogView::event( QEvent* event )
{
bool res = QListView::event( event );
if ( event->type() == QEvent::Paint ) repaintViewport();
return res;
}
void WGLogView::resizeEvent( QResizeEvent* event )
{
QListView::resizeEvent( event );
repaintViewport();
}
void WGLogView::repaintViewport()
{
int new_w = clipper()->width() - header()->sectionSize( column_margin );
header()->resizeSection( column_log, new_w );
QListViewItem* item = firstChild();
QRect rect;
while ( item ) {
rect = itemRect( item );
if ( rect.top() > -item->height() ) item->repaint();
item = item->itemBelow();
}
}
void WGLogView::insertOutStrList( WGUnicodeLog& strList, const bool new_line )
{
for ( unsigned int i = 0; i < strList.unicode_count(); i++ ) {
if ( !new_line && i == 0 && lastItem() ) {
WGLogViewItem* item = (WGLogViewItem*)lastItem();
item->setText( column_log, item->text(column_log) + strList.unicode_at(i) );
} else {
WGLogViewItem* item = new WGLogViewItem( this );
item->setText( column_log, strList.unicode_at(i) );
}
}
focusLastItem();
}
void WGLogView::vertScrollBarValueChanged( int )
{
canFocusLastItem = verticalScrollBar()->value() == verticalScrollBar()->maxValue();
}
void WGLogView::focusLastItem( const bool always )
{
if ( (canFocusLastItem || always ) && lastItem() ) {
ensureItemVisible( lastItem() );
setCurrentItem( lastItem() );
}
}
// -------------------------------------------------------
// -------- WGLogViewItem
// -------------------------------------------------------
WGLogViewItem::WGLogViewItem( const WGLogView* const parent ): QListViewItem( (QListView*)parent, parent->lastItem() )
{
setSelectable( false );
}
WGLogViewItem::~WGLogViewItem()
{
}
void WGLogViewItem::paintCell( QPainter* painter, const QColorGroup&, int column, int width, int )
{
if ( painter ) {
WGLogView* logList = (WGLogView*)listView();
int w = width;
int h = height();
painter->fillRect( 0, 0, w, h, logList->paletteBackgroundColor() );
if ( column == column_log ) {
QString propName = text( column_log );
painter->setPen( logList->paletteForegroundColor() );
painter->drawText( 0, 0, w, h - 1, AlignVCenter, propName );
}
}
}
void WGLogViewItem::paintFocus( QPainter*, const QColorGroup&, const QRect& )
{
return;
}