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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/***************************************************************************
* Copyright (C) 2003 by Jens Dagerbo *
* jens.dagerbo@swipnet.se *
* *
* 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 <tqpainter.h>
#include <tqstyle.h>
#include <tqpalette.h>
#include <tqcheckbox.h>
#include "replaceitem.h"
bool ReplaceItem::s_listview_done = false;
bool ReplaceItem::hasCheckedChildren() const
{
ReplaceItem const * item = firstChild();
while ( item )
{
if ( item->isOn() )
{
return true;
}
item = item->nextSibling();
}
return false;
}
void ReplaceItem::stateChange( bool state )
{
if ( s_listview_done && justClicked() )
{
setChecked( state );
}
}
void ReplaceItem::setChecked( bool checked )
{
if ( !isFile() ) // this is a child item
{
if ( checked || !(parent()->hasCheckedChildren()))
{
if ( parent()->isOn() != checked )
{
parent()->_clicked = false;
parent()->setOn( checked );
}
}
return;
}
// this is a parent item, set self and tqchildren
ReplaceItem * item = firstChild();
while ( item )
{
if ( item->isOn() != checked )
{
item->_clicked = false;
item->setOn( checked );
}
item = item->nextSibling();
}
}
// code mostly lifted from TQCheckListItem::paintCell()
void ReplaceItem::paintCell( TQPainter * p, const TQColorGroup & cg, int column, int width, int align )
{
if ( !p )
return;
TQListView *lvv = listView();
if ( !lvv )
return;
ReplaceView * lv = static_cast<ReplaceView*>(lvv);
const BackgroundMode bgmode = lv->viewport()->backgroundMode();
const TQColorGroup::ColorRole crole = TQPalette::backgroundRoleFromMode( bgmode );
if ( cg.brush( crole ) != lv->colorGroup().brush( crole ) )
p->fillRect( 0, 0, width, height(), cg.brush( crole ) );
else
lv->paintEmptyArea( p, TQRect( 0, 0, width, height() ) );
TQFontMetrics fm( lv->fontMetrics() );
int boxsize = lv->tqstyle().pixelMetric(TQStyle::PM_CheckListButtonSize, lv);
int marg = lv->itemMargin();
int r = marg;
// Draw controller / checkbox / radiobutton ---------------------
int styleflags = TQStyle::Style_Default;
if ( isOn() )
styleflags |= TQStyle::Style_On;
else
styleflags |= TQStyle::Style_Off;
if ( isSelected() )
styleflags |= TQStyle::Style_Selected;
if ( isEnabled() && lv->isEnabled() )
styleflags |= TQStyle::Style_Enabled;
int x = 0;
int y = 0;
x += 3;
if ( align & AlignVCenter )
y = ( ( height() - boxsize ) / 2 ) + marg;
else
y = (fm.height() + 2 + marg - boxsize) / 2;
lv->tqstyle().tqdrawPrimitive(TQStyle::PE_CheckListIndicator, p,
TQRect(x, y, boxsize,
fm.height() + 2 + marg),
cg, styleflags, TQStyleOption(this));
r += boxsize + 4;
// Draw text ----------------------------------------------------
p->translate( r, 0 );
p->setPen( TQPen( cg.text() ) );
TQColorGroup mcg = cg;
mcg.setColor( TQColorGroup::Text, ( isFile() ? TQt::darkGreen : TQt::blue ) );
mcg.setColor( TQColorGroup::HighlightedText, ( isFile() ? TQt::darkGreen : TQt::blue ) );
TQListViewItem::paintCell( p, mcg, column, width - r, align );
}
void ReplaceItem::activate( int, TQPoint const & localPos )
{
TQListView * lv = listView();
TQCheckBox cb(0);
int boxsize = cb.sizeHint().width();
//that's KDE-3.1 only int boxsize = lv->style().pixelMetric(TQStyle::PM_CheckListButtonSize, lv);
int rightside = lv->itemMargin() + boxsize + ( isFile() ? 0 : lv->treeStepSize() );
// _lineclicked indicates if the click was on the line or in the checkbox
_lineclicked = rightside < localPos.x();
}
|