1
/***************************************************************************
2
qmultichecklistitem.cpp - description
4
begin : Sun Jan 26 2003
5
copyright : (C) 2003 by Jan Schäfer
6
email : janschaefer@users.sourceforge.net
7
***************************************************************************/
9
/******************************************************************************
11
* This file is part of KSambaPlugin. *
13
* KSambaPlugin is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* KSambaPlugin is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with KSambaPlugin; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
27
******************************************************************************/
36
#include <kmessagebox.h>
38
#include "qmultichecklistitem.moc"
39
#include "qmultichecklistitem.h"
41
static const int BoxSize = 16;
44
QMultiCheckListItem::QMultiCheckListItem( Q3ListView *parent) :
45
Q3ListViewItem(parent)
49
void QMultiCheckListItem::resize(int column) {
50
if (column >= (int) checkBoxColumns.size()) {
51
checkBoxColumns.resize(column*2);
52
checkStates.resize(column*2);
53
disableStates.resize(column*2);
58
void QMultiCheckListItem::setOn(int column, bool b) {
60
checkStates.setBit(column,b);
61
checkBoxColumns.setBit(column);
62
kDebug(5009) << "setOn : " << column;
66
bool QMultiCheckListItem::isOn(int column) {
68
return checkStates.testBit(column);
71
bool QMultiCheckListItem::isDisabled(int column) {
73
return disableStates.testBit(column);
76
void QMultiCheckListItem::toggle(int column) {
78
checkBoxColumns.setBit(column);
79
checkStates.toggleBit(column);
80
emit stateChanged(column,checkStates.testBit(column));
85
void QMultiCheckListItem::setDisabled(int column, bool b) {
88
disableStates.setBit(column,b);
89
// KMessageBox::information(0L,QString("setDisabled"),QString("disable %1 ").arg(column));
93
void QMultiCheckListItem::paintCell(QPainter *p,const QColorGroup & cg, int col, int width, int align)
100
Q3ListView *lv = listView();
104
Q3ListViewItem::paintCell(p,cg,col,width,align );
106
int marg = lv->itemMargin();
107
// int width = BoxSize + marg*2;
108
// use a provate color group and set the text/highlighted text colors
109
QColorGroup mcg = cg;
111
if (checkBoxColumns.testBit(col)) {
112
// Bold/Italic/use default checkboxes
113
// code almost identical to QCheckListItem
114
Q_ASSERT( lv ); //###
115
// I use the text color of defaultStyles[0], normalcol in parent listview
116
// mcg.setColor( QPalette::Text, ((StyleListView*)lv)->normalcol );
118
if ( align == Qt::AlignCenter ) {
119
QFontMetrics fm( lv->font() );
120
x = (width - BoxSize - fm.width(text(0)))/2;
122
int y = (height() - BoxSize) / 2;
124
if ( !isEnabled() || disableStates.testBit(col))
125
p->setPen( QPen( lv->palette().color( QPalette::Disabled, QPalette::Text ), 2 ) );
127
p->setPen( QPen( mcg.text(), 2 ) );
129
if ( isSelected() && lv->header()->mapToSection( 0 ) != 0 ) {
130
p->fillRect( 0, 0, x + marg + BoxSize + 4, height(),
131
mcg.brush( QPalette::Highlight ) );
133
p->setPen( QPen( mcg.color( QPalette::HighlightedText), 2 ) ); // FIXME! - use defaultstyles[0].selecol. luckily not used :)
135
p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
138
if ( checkStates.testBit(col) ) {
143
for ( i=0; i<3; i++ ) {
144
a.setPoint( 2*i, xx, yy );
145
a.setPoint( 2*i+1, xx, yy+2 );
149
for ( i=3; i<7; i++ ) {
150
a.setPoint( 2*i, xx, yy );
151
a.setPoint( 2*i+1, xx, yy+2 );
154
p->drawLineSegments( a );