summaryrefslogtreecommitdiffstats
path: root/kghostview/marklist.cpp
blob: 259d13a1adcf1b93227f97b817f7bc09ea3989e6 (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/**
 * Copyright (C) 1997-2002 the KGhostView authors. See file AUTHORS.
 *
 * 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "marklist.moc"

#include <cassert>

#include <tqimage.h>
#include <layout.h>
#include <tqtooltip.h>
#include <tqlabel.h>
#include <tqwhatsthis.h>

#include <kglobalsettings.h>
#include <klocale.h>
#include <kdebug.h>

#include "kgv_miniwidget.h"

MarkListItem::MarkListItem(TQWidget *parent, const TQString &text, const TQString &tip, const TQColor &color, KGVMiniWidget* miniW, int pageNum)
    : TQWidget( parent ),
    _miniWidget( miniW ),
    _pageNum( pageNum ),
    _requested( false )
{
    //kdDebug( 4500 ) << "MarkListItem::MarkListItem( _ , "  << text <<" , " << tip << " , " <<  color << ", _ ," << pageNum << " )" << endl;
    TQBoxLayout *l = new TQVBoxLayout( this, 5, 0 );
    _thumbnailW = new TQWidget( this );
    _checkBox = new TQCheckBox( text, this );
    l->addWidget( _thumbnailW, 1 );
    l->addWidget( _checkBox, 0, TQt::AlignHCenter );
    TQWhatsThis::add( _checkBox, i18n( "Using this checkbox you can select pages for printing." ) );
    setFixedHeight( 100 );
    _backgroundColor = color;
    setPaletteBackgroundColor( _backgroundColor );
    TQToolTip::add(this, tip);
    // TODO: Put a little page number or other place-holder when there is no thumbnail to display.
}

bool MarkListItem::isChecked() const
{
    return _checkBox->isChecked();
}

void MarkListItem::toggle()
{
    _checkBox->toggle();
}

void MarkListItem::setChecked( bool checked )
{
    _checkBox->setChecked(checked);
}

void MarkListItem::setPixmap( TQPixmap thumbnail )
{
    // The line below is needed to work around certain "features" of styles such as liquid
    // see bug:61711 for more info (LPC, 20 Aug '03)
    _thumbnailW->setBackgroundOrigin( TQWidget::WidgetOrigin );
    TQPixmap pm;
    pm.convertFromImage( thumbnail.convertToImage().smoothScale( _thumbnailW->size() ) );
    _thumbnailW->setPaletteBackgroundPixmap( pm );
    _requested = false;
}

void MarkListItem::setSelected( bool selected )
{
    if (selected)
	setPaletteBackgroundColor( TQApplication::palette().active().highlight() );
    else
	setPaletteBackgroundColor( _backgroundColor );
}

void MarkListItem::resizeEvent( TQResizeEvent * )
{
    if ( _thumbnailW->paletteBackgroundPixmap() ) {
	TQPixmap pm;
	pm.convertFromImage( _thumbnailW->paletteBackgroundPixmap()->convertToImage().smoothScale( _thumbnailW->size() ) );
	_thumbnailW->setPaletteBackgroundPixmap( pm );
    }
}

void MarkListItem::paintEvent( TQPaintEvent* )
{
    /* TODO:
     * We should cancel things which flipped into view and then flipped out.
     *
     * Now, if one scrolls through a 1000 page document to the end and then lingers on the
     * last pages, these will take forever to appear in thumbnail form.
     */
    if ( _requested ) return;
    if ( !_thumbnailW->paletteBackgroundPixmap() ||  _thumbnailW->paletteBackgroundPixmap()->isNull() ) {
	_miniWidget->getThumbnailService()->delayedGetThumbnail( _pageNum, TQT_TQOBJECT(this), TQT_SLOT( setPixmap( TQPixmap ) ) );
	_requested = true;
    }
}


/* MarkList */

MarkList::MarkList( TQWidget* parent, const char* name, KGVMiniWidget* mini)
    : TQTable( parent, name ),
    _selected ( -1 ),
_miniWidget( mini )
{
    setNumCols( 1 );
    setLeftMargin( 0 ); // we don't want the vertical header
    horizontalHeader()->setLabel( 0, i18n("Page") );

    connect( this, TQT_SIGNAL( currentChanged( int, int ) ),
	    this, TQT_SIGNAL( selected( int ) ) );
}

TQValueList<int> MarkList::markList() const
{
    TQValueList<int> list;
    MarkListItem *_item;
    for(int i = 0; i < numRows(); i++)
    {
	_item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) );
	assert( _item );
	if ( _item->isChecked() ) list << (i + 1);
    }
    return list;
}

void MarkList::insertItem( const TQString& text, int index, const TQString& tip)
{
    MarkListItem *_item;
    _item = new MarkListItem( this, text, tip, viewport()->paletteBackgroundColor(), _miniWidget, index );
    setNumRows( index + 1 );
    setCellWidget( index, 0, _item );
    setRowHeight( index, _item->height() );
}

void MarkList::select( int index )
{
    MarkListItem *_item;
    setCurrentCell( index, 0 );
    _item = dynamic_cast<MarkListItem *>( cellWidget( _selected, 0 ) );
    if (_item) _item -> setSelected( false );
    _selected = index;
    _item = dynamic_cast<MarkListItem *>( cellWidget( _selected, 0 ) );
    if (_item) _item -> setSelected( true );
    clearFocus();
}

void MarkList::clear()
{
    for ( int i = 0; i != numRows() ; ++i ) {
	clearCellWidget( i, 0 );
    }
    setNumRows( 0 );
}

void MarkList::markCurrent()
{
    MarkListItem *_item = dynamic_cast<MarkListItem *>( cellWidget( currentRow(), 0 ) );
    assert( _item );
    _item->toggle();
}

void MarkList::markAll()
{
    MarkListItem *_item;
    for(int i = 0; i < numRows(); i++)
    {
	_item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) );
	assert( _item );
	_item->setChecked( true );
    }
}

void MarkList::markEven()
{
    MarkListItem *_item;
    for(int i = 1; i < numRows(); i = i + 2)
    {
	_item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) );
	assert( _item );
	_item->setChecked( true );
    }
}

void MarkList::markOdd()
{
    MarkListItem *_item;
    for(int i = 0; i < numRows(); i = i + 2)
    {
	_item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) );
	assert( _item );
	_item->setChecked( true );
    }
}

void MarkList::toggleMarks()
{
    MarkListItem *_item;
    for(int i = 0; i < numRows(); i++)
    {
	_item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) );
	assert( _item );
	_item->toggle();
    }
}

void MarkList::removeMarks()
{
    MarkListItem *_item;
    for( int i = 0; i < numRows(); i++ ) {
	_item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) );
	assert( _item );
	_item->setChecked( false );
    }
}

void MarkList::viewportResizeEvent ( TQResizeEvent * )
{
    MarkListItem *_item;
    if( visibleWidth() != columnWidth( 0 ) )
    {
	setColumnWidth( 0, visibleWidth() );
	for( int i = 0; i < numRows(); ++i )
	{
	    _item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) );
	    assert( _item );
	    _item->setFixedSize( visibleWidth(), _item->height() );
	}
    }
}

// vim:sw=4:sts=4:ts=8:noet