File: ViewTableItem.cpp

package info (click to toggle)
bsc 2.27-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,640 kB
  • ctags: 2,610
  • sloc: cpp: 14,100; perl: 114; makefile: 46
file content (130 lines) | stat: -rw-r--r-- 5,203 bytes parent folder | download | duplicates (2)
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
/********************************************************************
 * Copyright (C) 2005 Piotr Pszczolkowski
 *-------------------------------------------------------------------
 * This file is part of BsC (Beesoft Commander).
 *
 * BsC 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.
 *
 * BsC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with BsC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *******************************************************************/

/*------- include files:
-------------------------------------------------------------------*/
#include "ViewTable.h"
#include "ViewTableItem.h"
#include "Shared.h"

/*------- local constants:
-------------------------------------------------------------------*/
const QColor ViewTableItem::BG_NoFocusSelected           = qRgb( 211, 211, 191 );
const QColor ViewTableItem::BG_NoFocusCurrent            = qRgb( 147, 177, 177 );
const QColor ViewTableItem::BG_NoFocusCurrentAndSelected = qRgb( 147, 177, 177 );

const QColor ViewTableItem::FOCUSED_NUMBER_TEXT      = qRgb( 255, 0, 0 );
const QColor ViewTableItem::FOCUSED_NUMBER_SELTEXT   = qRgb( 255, 220, 0 );
const QColor ViewTableItem::NOFOCUSED_NUMBER_TEXT    = qRgb( 235, 150, 122 );

const QColor ViewTableItem::DEFAULT_CURRENT_SELECTED_FG = qRgb( 0, 0, 0 );
const QColor ViewTableItem::DEFAULT_CURRENT_SELECTED_BG = qRgb( 255, 159, 173 );
const QColor ViewTableItem::DEFAULT_CURRENT_FG          = qRgb( 0, 0, 0 );
const QColor ViewTableItem::DEFAULT_CURRENT_BG          = qRgb( 153, 204, 153 );
const QColor ViewTableItem::DEFAULT_SELECTED_FG         = qRgb( 255, 255, 255 );
const QColor ViewTableItem::DEFAULT_SELECTED_BG         = qRgb( 154, 167, 255 );

//*******************************************************************
// paintCell                                       PRIVATE inherited
//*******************************************************************
void ViewTableItem::paintCell( QPainter* p, const QColorGroup& cg, int col, int w, int align )
{
	QColorGroup new_cg = cg;
	
	if(( 3 == col ) && d_is_size_computed ) {
		if( listView()->hasFocus() ) {
			new_cg.setColor( QColorGroup::Text, FOCUSED_NUMBER_TEXT );
			new_cg.setColor( QColorGroup::HighlightedText, FOCUSED_NUMBER_SELTEXT );
		}	
		else {
			new_cg.setColor( QColorGroup::Text, NOFOCUSED_NUMBER_TEXT );
			new_cg.setColor( QColorGroup::HighlightedText, NOFOCUSED_NUMBER_TEXT );
		}
	}
	
	const bool is_current = ( this == listView()->currentItem() );
	const bool is_selected = isSelected();
	
	if( listView()->hasFocus() ) {		
		if( is_current && is_selected ) {
			new_cg.setColor( QColorGroup::HighlightedText, DEFAULT_CURRENT_SELECTED_FG );
			new_cg.setColor( QColorGroup::Highlight, DEFAULT_CURRENT_SELECTED_BG );
		}
		else if( is_current ) {
			new_cg.setColor( QColorGroup::Text, DEFAULT_CURRENT_FG );
			new_cg.setColor( QColorGroup::Base, DEFAULT_CURRENT_BG );
		}
		else if( is_selected ) {
			new_cg.setColor( QColorGroup::HighlightedText, DEFAULT_SELECTED_FG );
			new_cg.setColor( QColorGroup::Highlight, DEFAULT_SELECTED_BG );
		}
	}
	else {
		if( is_selected && is_current ) {
			new_cg.setColor( QColorGroup::Highlight, BG_NoFocusCurrentAndSelected );
		}
		else if( is_selected ) {
			new_cg.setColor( QColorGroup::Highlight, BG_NoFocusSelected );
		}
		else if( is_current  ) {
			new_cg.setColor( QColorGroup::Text, QColor( 255, 255, 255 ) );
			new_cg.setColor( QColorGroup::Base, BG_NoFocusCurrent );
		}
	}
	QListViewItem::paintCell( p, new_cg, col, w, align );
}
// end of paintCell

//*******************************************************************
// compare                                         PRIVATE inherited
//*******************************************************************
int ViewTableItem::compare( QListViewItem* in_item, int in_column, bool in_ascending ) const
{
	int retval = 0;

	if( Shared::ParentDir == text( 0 )) {
		retval = ( in_ascending ) ? -1 : 1;
	}
	else if( Shared::ParentDir == in_item->text( 0 )) {
		retval = (in_ascending ) ? 1 : -1;
	}
	else {
		const bool item_isdir = ( in_item->text( 2 )[0] == 'd' );
		const bool im_isdir   = ( text( 2 )[0] == 'd' );
		if( item_isdir && !im_isdir ) {
			retval = ( in_ascending ) ? 1 : -1;
		}
		else if( im_isdir && !item_isdir ) {
			retval = ( in_ascending ) ? -1 : 1;
		}
		else {
			if( 3 == in_column ) {
				const Q_ULLONG first_value  = in_item->text( in_column ).remove( ',' ).toLong();
				const Q_ULLONG second_value = text( in_column ).remove( ',' ).toLong();
				retval = ( first_value < second_value ) ?  1 : -1;
			}
			else {
				retval = key( in_column, in_ascending ).compare( in_item->key( in_column, in_ascending ));
			}
		}
	}
	
	return retval;
}