From 32ace734b36de108d8322157aaa106069df16477 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 17:25:43 -0600 Subject: Fix FTBFS --- kghostview/marklist.cpp | 247 ------------------- kghostview/marklist.h | 90 ------- kghostview/martdelist.cpp | 247 +++++++++++++++++++ kghostview/martdelist.h | 90 +++++++ kviewshell/marklist.cpp | 616 ---------------------------------------------- kviewshell/marklist.h | 189 -------------- kviewshell/martdelist.cpp | 616 ++++++++++++++++++++++++++++++++++++++++++++++ kviewshell/martdelist.h | 189 ++++++++++++++ 8 files changed, 1142 insertions(+), 1142 deletions(-) delete mode 100644 kghostview/marklist.cpp delete mode 100644 kghostview/marklist.h create mode 100644 kghostview/martdelist.cpp create mode 100644 kghostview/martdelist.h delete mode 100644 kviewshell/marklist.cpp delete mode 100644 kviewshell/marklist.h create mode 100644 kviewshell/martdelist.cpp create mode 100644 kviewshell/martdelist.h diff --git a/kghostview/marklist.cpp b/kghostview/marklist.cpp deleted file mode 100644 index 9505b965..00000000 --- a/kghostview/marklist.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/** - * 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 - -#include -#include -#include -#include -#include - -#include -#include -#include - -#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 MarkList::markList() const -{ - TQValueList list; - MarkListItem *_item; - for(int i = 0; i < numRows(); i++) - { - _item = dynamic_cast( 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( cellWidget( _selected, 0 ) ); - if (_item) _item -> setSelected( false ); - _selected = index; - _item = dynamic_cast( 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( cellWidget( currentRow(), 0 ) ); - assert( _item ); - _item->toggle(); -} - -void MarkList::markAll() -{ - MarkListItem *_item; - for(int i = 0; i < numRows(); i++) - { - _item = dynamic_cast( 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( 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( cellWidget( i, 0 ) ); - assert( _item ); - _item->setChecked( true ); - } -} - -void MarkList::toggleMarks() -{ - MarkListItem *_item; - for(int i = 0; i < numRows(); i++) - { - _item = dynamic_cast( cellWidget( i, 0 ) ); - assert( _item ); - _item->toggle(); - } -} - -void MarkList::removeMarks() -{ - MarkListItem *_item; - for( int i = 0; i < numRows(); i++ ) { - _item = dynamic_cast( 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( cellWidget( i, 0 ) ); - assert( _item ); - _item->setFixedSize( visibleWidth(), _item->height() ); - } - } -} - -// vim:sw=4:sts=4:ts=8:noet diff --git a/kghostview/marklist.h b/kghostview/marklist.h deleted file mode 100644 index 54992a88..00000000 --- a/kghostview/marklist.h +++ /dev/null @@ -1,90 +0,0 @@ -/** - * 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. - */ - -#ifndef MARKLIST_H -#define MARKLIST_H - -#include -#include - -class KGVMiniWidget; - -class MarkListItem : public TQWidget -{ - Q_OBJECT - -public: - MarkListItem( TQWidget *parent, const TQString &text, const TQString &tip, const TQColor &color, KGVMiniWidget*, int ); - - bool isChecked() const; - -public slots: - void toggle(); - void setChecked( bool checked ); - void setPixmap( TQPixmap thumbnail ); - - void setSelected( bool selected ); - -private: - void resizeEvent( TQResizeEvent * ); - void paintEvent( TQPaintEvent* ); -private: - TQWidget *_thumbnailW; - TQCheckBox *_checkBox; - TQColor _backgroundColor; - KGVMiniWidget* _miniWidget; - const int _pageNum; - bool _requested; -}; - -class MarkList: public TQTable -{ - Q_OBJECT - - -public: - MarkList( TQWidget* parent = 0, const char* name = 0, KGVMiniWidget* = 0 ); - - TQValueList markList() const; - void insertItem( const TQString& text, int index = -1, - const TQString& tip = TQString() ); - -public slots: - void select( int index ); - void markCurrent(); - void markAll(); - void markEven(); - void markOdd(); - void toggleMarks(); - void removeMarks(); - void clear(); - -protected: - virtual void viewportResizeEvent ( TQResizeEvent * ); - -signals: - void selected( int ); - -private: - int _selected; - KGVMiniWidget* _miniWidget; -}; - -#endif - -// vim:sw=4:sts=4:ts=8:noet diff --git a/kghostview/martdelist.cpp b/kghostview/martdelist.cpp new file mode 100644 index 00000000..9505b965 --- /dev/null +++ b/kghostview/martdelist.cpp @@ -0,0 +1,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 + +#include +#include +#include +#include +#include + +#include +#include +#include + +#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 MarkList::markList() const +{ + TQValueList list; + MarkListItem *_item; + for(int i = 0; i < numRows(); i++) + { + _item = dynamic_cast( 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( cellWidget( _selected, 0 ) ); + if (_item) _item -> setSelected( false ); + _selected = index; + _item = dynamic_cast( 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( cellWidget( currentRow(), 0 ) ); + assert( _item ); + _item->toggle(); +} + +void MarkList::markAll() +{ + MarkListItem *_item; + for(int i = 0; i < numRows(); i++) + { + _item = dynamic_cast( 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( 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( cellWidget( i, 0 ) ); + assert( _item ); + _item->setChecked( true ); + } +} + +void MarkList::toggleMarks() +{ + MarkListItem *_item; + for(int i = 0; i < numRows(); i++) + { + _item = dynamic_cast( cellWidget( i, 0 ) ); + assert( _item ); + _item->toggle(); + } +} + +void MarkList::removeMarks() +{ + MarkListItem *_item; + for( int i = 0; i < numRows(); i++ ) { + _item = dynamic_cast( 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( cellWidget( i, 0 ) ); + assert( _item ); + _item->setFixedSize( visibleWidth(), _item->height() ); + } + } +} + +// vim:sw=4:sts=4:ts=8:noet diff --git a/kghostview/martdelist.h b/kghostview/martdelist.h new file mode 100644 index 00000000..54992a88 --- /dev/null +++ b/kghostview/martdelist.h @@ -0,0 +1,90 @@ +/** + * 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. + */ + +#ifndef MARKLIST_H +#define MARKLIST_H + +#include +#include + +class KGVMiniWidget; + +class MarkListItem : public TQWidget +{ + Q_OBJECT + +public: + MarkListItem( TQWidget *parent, const TQString &text, const TQString &tip, const TQColor &color, KGVMiniWidget*, int ); + + bool isChecked() const; + +public slots: + void toggle(); + void setChecked( bool checked ); + void setPixmap( TQPixmap thumbnail ); + + void setSelected( bool selected ); + +private: + void resizeEvent( TQResizeEvent * ); + void paintEvent( TQPaintEvent* ); +private: + TQWidget *_thumbnailW; + TQCheckBox *_checkBox; + TQColor _backgroundColor; + KGVMiniWidget* _miniWidget; + const int _pageNum; + bool _requested; +}; + +class MarkList: public TQTable +{ + Q_OBJECT + + +public: + MarkList( TQWidget* parent = 0, const char* name = 0, KGVMiniWidget* = 0 ); + + TQValueList markList() const; + void insertItem( const TQString& text, int index = -1, + const TQString& tip = TQString() ); + +public slots: + void select( int index ); + void markCurrent(); + void markAll(); + void markEven(); + void markOdd(); + void toggleMarks(); + void removeMarks(); + void clear(); + +protected: + virtual void viewportResizeEvent ( TQResizeEvent * ); + +signals: + void selected( int ); + +private: + int _selected; + KGVMiniWidget* _miniWidget; +}; + +#endif + +// vim:sw=4:sts=4:ts=8:noet diff --git a/kviewshell/marklist.cpp b/kviewshell/marklist.cpp deleted file mode 100644 index 1cbf6581..00000000 --- a/kviewshell/marklist.cpp +++ /dev/null @@ -1,616 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2004 Wilfried Huss - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "documentPageCache.h" -#include "kvsprefs.h" -#include "marklist.h" - - -#include "marklist.moc" - - -namespace { - -/** Holds the icon used as a overlay on pages which are not drawn yet. */ -TQPixmap* waitIcon = 0; - -} // namespace anon - - -/****** ThumbnailWidget ******/ - -ThumbnailWidget::ThumbnailWidget(MarkListWidget* _parent, const PageNumber& _pageNumber, DocumentPageCache* _pageCache) - : TQWidget(_parent), pageNumber(_pageNumber), pageCache(_pageCache), parent(_parent) -{ - setBackgroundMode(TQt::NoBackground); - - needsUpdating = true; - - if (!waitIcon) - { - waitIcon = new TQPixmap(TDEGlobal::iconLoader()->loadIcon("gear", KIcon::NoGroup, KIcon::SizeMedium)); - } -} - -void ThumbnailWidget::paintEvent(TQPaintEvent* e) -{ - // Only repaint if the widget is really visible. We need to check this because TQt - // sends paintEvents to all widgets that have ever been visible in the Scrollview - // whenever the ScrollView is resized. This also increases the percieved performance - // only thumbnails that are really needed are rendered. - if (!parent->isVisible()) - { - //kdDebug() << "Abort Thumbnail drawing for page " << pageNumber << endl; - return; - } - - TQPainter p(this); - p.setClipRect(e->rect()); - - // Paint a black border around the widget - p.setRasterOp(TQt::CopyROP); - p.setBrush(NoBrush); - p.setPen(TQt::black); - p.drawRect(rect()); - - // Remove 1 pixel from all sides of the rectangle, to eliminate overdraw with - // the black border. - TQRect thumbRect = rect(); - thumbRect.addCoords(1,1,-1,-1); - - // If the thumbnail is empty or has been marked for updating generate a new thumbnail. - if (thumbnail.isNull() || needsUpdating) - { - if (KVSPrefs::changeColors() && KVSPrefs::renderMode() == KVSPrefs::EnumRenderMode::Paper) - p.fillRect(thumbRect, KVSPrefs::paperColor()); - else - p.fillRect(thumbRect, TQt::white); - - // Draw busy indicator. - // Im not really sure if this is a good idea. - // While it is nice to see an indication that something is happening for pages which - // take long to redraw, it gets quite annoing for fast redraws. - // TODO: Disable or find something less distractiong. - p.drawPixmap(10, 10, *waitIcon); - - TQTimer::singleShot(50, this, TQT_SLOT(setThumbnail())); - return; - } - - // Safety check - if (thumbnail.isNull()) - { - kdDebug(1223) << "No Thumbnail for page " << pageNumber << " created." << endl; - return; - } - - - // The actual page starts at point (1,1) because of the outline. - // Therefore we need to shift the destination rectangle. - TQRect pixmapRect = thumbRect; - pixmapRect.moveBy(-1,-1); - - // Paint widget - bitBlt (this, thumbRect.topLeft(), &thumbnail, pixmapRect, CopyROP); -} - -void ThumbnailWidget::resizeEvent(TQResizeEvent*) -{ - thumbnail.resize(width(), height()); - // Generate a new thumbnail in the next paintEvent. - needsUpdating = true; -} - -void ThumbnailWidget::setThumbnail() -{ - if (!parent->isVisible()) - { - // We only want to calculate the thumbnail for widgets that are currently visible. - // When we are fast scrolling thru the document. Many paint events are created, that - // are often not needed anymore at the time the eventloop executes them. - //kdDebug() << "Delayed request Abort Thumbnail drawing for page " << pageNumber << endl; - kapp->processEvents(); - return; - } - - needsUpdating = false; - - // Draw Thumbnail - thumbnail = pageCache->createThumbnail(pageNumber, width() - 2); - - if (thumbnail.height() != height() + 2) - setFixedHeight(thumbnail.height() + 2); - - update(); - kapp->processEvents(); -} - - -/****** MarkListWidget ******/ - - -MarkListWidget::MarkListWidget(TQWidget* _parent, MarkList* _markList, const PageNumber& _pageNumber, - DocumentPageCache* _pageCache, bool _showThumbnail) - : TQWidget(_parent), showThumbnail(_showThumbnail), pageNumber(_pageNumber), - pageCache(_pageCache), markList(_markList) -{ - TQBoxLayout* layout = new TQVBoxLayout(this, margin); - - thumbnailWidget = 0; - if (showThumbnail) - { - thumbnailWidget = new ThumbnailWidget(this, pageNumber, pageCache); - layout->addWidget(thumbnailWidget, 1, TQt::AlignTop); - } - - TQBoxLayout* bottomLayout = new TQHBoxLayout(layout); - - checkBox = new TQCheckBox(TQString(), this ); - checkBox->setFocusPolicy(TQ_NoFocus); - TQToolTip::add(checkBox, i18n("Select for printing")); - bottomLayout->addWidget(checkBox, 0, TQt::AlignAuto); - - pageLabel = new TQLabel(TQString("%1").arg(pageNumber), this); - bottomLayout->addWidget(pageLabel, 1); - - _backgroundColor = TDEGlobalSettings::baseColor(); - - // Alternate between colors. - if ((pageNumber % 2 == 0) && TDEGlobalSettings::alternateBackgroundColor().isValid()) - _backgroundColor = TDEGlobalSettings::alternateBackgroundColor(); - - setPaletteBackgroundColor( _backgroundColor ); - - show(); -} - -bool MarkListWidget::isChecked() const -{ - return checkBox->isChecked(); -} - -void MarkListWidget::toggle() -{ - checkBox->toggle(); -} - -void MarkListWidget::setChecked( bool checked ) -{ - checkBox->setChecked(checked); -} - -void MarkListWidget::setSelected( bool selected ) -{ - if (selected) - setPaletteBackgroundColor( TQApplication::palette().active().highlight() ); - else - setPaletteBackgroundColor( _backgroundColor ); -} - -int MarkListWidget::setNewWidth(int width) -{ - int height = TQMAX(checkBox->height(), pageLabel->height()) + 2*margin; - if (showThumbnail) - { - // Calculate size of Thumbnail - int thumbnailWidth = TQMIN(width, KVSPrefs::maxThumbnailWidth()); - int thumbnailHeight = (int)((thumbnailWidth - 2*margin - 2) / pageCache->sizeOfPage(pageNumber).aspectRatio() + 0.5) + 2; - - // Resize Thumbnail if necessary - if (thumbnailWidget->size() != TQSize(thumbnailWidth, thumbnailHeight)) - thumbnailWidget->setFixedSize(thumbnailWidth - 2*margin, thumbnailHeight); - - height += thumbnailHeight + 2*margin; - } - - setFixedSize(width, height); - return height; -} - -bool MarkListWidget::isVisible() -{ - TQRect visibleRect(markList->contentsX(), markList->contentsY(), - markList->visibleWidth(), markList->visibleHeight()); - TQRect widgetRect(markList->childX(this), markList->childY(this), width(), height()); - - if (widgetRect.intersects(visibleRect)) - return true; - - return false; -} - - -void MarkListWidget::mousePressEvent(TQMouseEvent* e) -{ - // Select Page - if (e->button() == Qt::LeftButton) - { - emit selected(pageNumber); - } - else if (e->button() == Qt::RightButton) - { - emit showPopupMenu(pageNumber, e->globalPos()); - } -} - - -/****** MarkList ******/ - - -MarkList::MarkList(TQWidget* parent, const char* name) - : TQScrollView(parent, name), clickedThumbnail(0), showThumbnails(true), contextMenu(0) -{ - currentPage = PageNumber::invalidPage; - widgetList.setAutoDelete(true); - setFocusPolicy( TQ_StrongFocus ); - //viewport()->setFocusPolicy( TQ_WheelFocus ); - setResizePolicy(TQScrollView::Manual); - - setVScrollBarMode(TQScrollView::AlwaysOn); - setHScrollBarMode(TQScrollView::AlwaysOff); - - setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding); - - viewport()->setBackgroundMode(TQt::PaletteBase); - enableClipper(true); -} - -MarkList::~MarkList() -{ - delete contextMenu; -} - -void MarkList::setPageCache(DocumentPageCache* _pageCache) -{ - pageCache = _pageCache; -} - -TQValueList MarkList::selectedPages() const -{ - TQValueList list; - MarkListWidget* item; - for(unsigned int i = 0; i < widgetList.count(); i++) - { - item = widgetList[i]; - if (item->isChecked()) - list << (i + 1); - } - return list; -} - -void MarkList::setNumberOfPages(int numberOfPages, bool _showThumbnails) -{ - showThumbnails = _showThumbnails; - - widgetList.resize(numberOfPages); - - int y = 0; - - for (int page = 1; page <= numberOfPages; page++) - { - MarkListWidget* item = new MarkListWidget(viewport(), this, page, pageCache, showThumbnails); - - connect(item, TQT_SIGNAL(selected(const PageNumber&)), this, TQT_SLOT(thumbnailSelected(const PageNumber&))); - connect(item, TQT_SIGNAL(showPopupMenu(const PageNumber&, const TQPoint&)), this, TQT_SLOT(showPopupMenu(const PageNumber&, const TQPoint&))); - - widgetList.insert(page - 1, item); - - int height = item->setNewWidth(visibleWidth()); - addChild(item, 0, y); - - y += height; - } - resizeContents(visibleWidth(), y); - viewport()->update(); -} - -void MarkList::thumbnailSelected(const PageNumber& pageNumber) -{ - // This variable is set to remember that the next call to setCurrentPageNumber - // has been initiated with a left click on the thumbnail of page pageNumber. - clickedThumbnail = pageNumber; - emit selected(pageNumber); -} - -void MarkList::setCurrentPageNumber(const PageNumber& pageNumber) -{ - if (!pageNumber.isValid() || pageNumber > (int)widgetList.count()) - { - clickedThumbnail = 0; - return; - } - - if (currentPage == pageNumber) - return; - - MarkListWidget* item; - - // Clear old selection - if (currentPage.isValid() && currentPage <= (int)widgetList.count()) - { - item = widgetList[currentPage - 1]; - item->setSelected(false); - } - - // Draw new selection - item = widgetList[pageNumber - 1]; - item->setSelected(true); - - // Make selected page visible if the current page has not been set with a mouseclick - // in the thumbnail list. (We use this because it is a bit confusing if the element that - // you have just clicked on, is scrolled away under the mouse cursor) - if (clickedThumbnail != pageNumber) - ensureVisible(childX(item), childY(item), 0, item->height()); - - clickedThumbnail = 0; - - currentPage = pageNumber; -} - -void MarkList::clear() -{ - currentPage = PageNumber::invalidPage; - widgetList.resize(0); -} - -void MarkList::selectAll() -{ - MarkListWidget* item; - for (unsigned int i = 0; i < widgetList.count(); i++) - { - item = widgetList[i]; - item->setChecked(true); - } -} - -void MarkList::selectEven() -{ - MarkListWidget* item; - for (unsigned int i = 1; i < widgetList.count(); i = i + 2) - { - item = widgetList[i]; - item->setChecked(true); - } -} - -void MarkList::selectOdd() -{ - MarkListWidget* item; - for (unsigned int i = 0; i < widgetList.count(); i = i + 2) - { - item = widgetList[i]; - item->setChecked(true); - } -} - -void MarkList::toggleSelection() -{ - MarkListWidget* item; - for (unsigned int i = 0; i < widgetList.count(); i++) - { - item = widgetList[i]; - item->toggle(); - } -} - -void MarkList::removeSelection() -{ - MarkListWidget* item; - for (unsigned int i = 0; i < widgetList.count(); i++) - { - item = widgetList[i]; - item->setChecked(false); - } -} - -void MarkList::viewportResizeEvent(TQResizeEvent*) -{ - MarkListWidget* item; - - int yold = contentsHeight(); - int y = 0; - - for (unsigned int i = 0; i < widgetList.count(); i++) - { - item = widgetList[i]; - int height = item->setNewWidth(visibleWidth()); - moveChild(item, 0, y); - - y += height; - } - resizeContents(visibleWidth(), y); - - // If the height of the content has changed - if (yold != contentsHeight()) - { - // Make sure the selected item is still visible. - if (currentPage.isValid() && currentPage <= (int)widgetList.count()) - { - item = widgetList[currentPage-1]; - ensureVisible(childX(item), childY(item), 0, item->height()); - } - } - - viewport()->update(); -} - - -void MarkList::updateWidgetSize(const PageNumber& pageNumber) -{ - // safety checks - if (!pageNumber.isValid() || pageNumber > widgetList.count()) - { - kdError() << "MarkList::updateWidgetSize called with invalid pageNumber " << pageNumber << endl; - return; - } - - MarkListWidget* item; - - // Resize the changed widget - item = widgetList[pageNumber - 1]; - int height = item->setNewWidth(visibleWidth()); - int y = childY(item) + height; - - // Move the rest of the widgets - for (unsigned int i = pageNumber; i < widgetList.count(); i++) - { - item = widgetList[i]; - int height = item->height(); - moveChild(item, 0, y); - - y += height; - } - resizeContents(contentsWidth(), y); - - viewport()->update(); -} - -void MarkList::mousePressEvent(TQMouseEvent* e) -{ - if (e->button() == Qt::RightButton) - { - // We call showPopupMenu with an invalid pageNumber to indicate that - // the mouse does not point at a thumbnailWidget. - showPopupMenu(PageNumber::invalidPage, e->globalPos()); - } -} - -void MarkList::slotShowThumbnails(bool show) -{ - if (show != showThumbnails) - { - int numOfPages = widgetList.count(); - - if (numOfPages == 0) - return; - - // Save current page. - PageNumber _currentPage = currentPage; - - // Save page selections. - TQValueVector selections; - selections.resize(widgetList.count()); - for (unsigned int i = 0; i < widgetList.count(); i++) - selections[i] = widgetList[i]->isChecked(); - - // Rebuild thumbnail widgets. - clear(); - setNumberOfPages(numOfPages, show); - - // Restore current page. - setCurrentPageNumber(_currentPage); - - // Restore page selections - for (unsigned int i = 0; i < widgetList.count(); i++) - widgetList[i]->setChecked(selections[i]); - } -} - - -void MarkList::repaintThumbnails() -{ - bool show = showThumbnails; - int numOfPages = widgetList.count(); - - // Rebuild thumbnail widgets. - clear(); - setNumberOfPages(numOfPages, show); -} - - -void MarkList::showPopupMenu(const PageNumber& pageNumber, const TQPoint& position) -{ - if (contextMenu == 0) - { - // Initialize Contextmenu - contextMenu = new TDEPopupMenu(this, "markListContext"); - - contextMenu->insertItem(i18n("Select &Current Page"), 0); - contextMenu->insertItem(i18n("Select &All Pages"), 1); - contextMenu->insertItem(i18n("Select &Even Pages"), 2); - contextMenu->insertItem(i18n("Select &Odd Pages"), 3); - contextMenu->insertItem(i18n("&Invert Selection"), 4); - contextMenu->insertItem(i18n("&Deselect All Pages"), 5); - } - - if (widgetList.count() == 0) - { - for (int i = 0; i <= 5; i++) - contextMenu->setItemEnabled(i, false); - } - else - { - for (int i = 0; i <= 5; i++) - contextMenu->setItemEnabled(i, true); - } - - // Only allow to select the current page if we got a valid pageNumber. - if (pageNumber.isValid() && pageNumber <= (int)widgetList.count()) - contextMenu->setItemEnabled(0, true); - else - contextMenu->setItemEnabled(0, false); - - // Show Contextmenu - switch(contextMenu->exec(position)) - { - case 0: - widgetList[pageNumber - 1]->toggle(); - break; - - case 1: - selectAll(); - break; - - case 2: - selectEven(); - break; - - case 3: - selectOdd(); - break; - - case 4: - toggleSelection(); - break; - - case 5: - removeSelection(); - break; - } -} - diff --git a/kviewshell/marklist.h b/kviewshell/marklist.h deleted file mode 100644 index 0ee15758..00000000 --- a/kviewshell/marklist.h +++ /dev/null @@ -1,189 +0,0 @@ -// -*- C++ -*- -/* This file is part of the KDE project - Copyright (C) 2004 Wilfried Huss - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef MARKLIST_H -#define MARKLIST_H - -#include "pageNumber.h" - -#include -#include -#include - -class TQCheckBox; -class TQLabel; -class TDEPopupMenu; - -class DocumentPageCache; - -class MarkList; -class MarkListWidget; - - -/****** ThumbnailWidget ******/ - - -class ThumbnailWidget : public TQWidget -{ - Q_OBJECT - - -public: - ThumbnailWidget(MarkListWidget* parent_, const PageNumber& _pageNumber, DocumentPageCache*); - -private: - virtual void paintEvent(TQPaintEvent*); - virtual void resizeEvent(TQResizeEvent*); - -private slots: - void setThumbnail(); - -private: - PageNumber pageNumber; - - bool needsUpdating; - - DocumentPageCache* pageCache; - - MarkListWidget* parent; - - TQPixmap thumbnail; -}; - - -/****** MarkListWidget ******/ - - -class MarkListWidget : public TQWidget -{ - Q_OBJECT - - -public: - MarkListWidget(TQWidget* _parent, MarkList*, const PageNumber& _pageNumber, DocumentPageCache*, bool _showThumbnail = true); - - bool isChecked() const; - - bool isVisible(); - -public slots: - void toggle(); - void setChecked( bool checked ); - - void setSelected( bool selected ); - - int setNewWidth(int width); - -signals: - /** Emitted when the Page is selected in the ThumbnailView. */ - void selected(const PageNumber&); - - /** Emitted on right click. */ - void showPopupMenu(const PageNumber& pageNumber, const TQPoint& position); - -protected: - virtual void mousePressEvent(TQMouseEvent*); - -private: - - bool showThumbnail; - - ThumbnailWidget* thumbnailWidget; - TQCheckBox* checkBox; - TQLabel* pageLabel; - TQColor _backgroundColor; - - const PageNumber pageNumber; - - DocumentPageCache* pageCache; - - static const int margin = 5; - - MarkList* markList; -}; - - -/****** MarkList ******/ - - -class MarkList: public TQScrollView -{ - Q_OBJECT - - -public: - MarkList(TQWidget* parent = 0, const char* name = 0); - virtual ~MarkList(); - - void setPageCache(DocumentPageCache*); - - TQValueList selectedPages() const; - - PageNumber currentPageNumber() { return currentPage; } - - PageNumber numberOfPages() { return widgetList.count(); } - - virtual TQSize sizeHint() const { return TQSize(); } - -public slots: - void setNumberOfPages(int numberOfPages, bool showThumbnails = true); - - void thumbnailSelected(const PageNumber& pageNumber); - void setCurrentPageNumber(const PageNumber& pageNumber); - - void clear(); - - void slotShowThumbnails(bool); - void repaintThumbnails(); - - void updateWidgetSize(const PageNumber&); - -protected: - virtual void viewportResizeEvent(TQResizeEvent*); - - virtual void mousePressEvent(TQMouseEvent*); - -signals: - void selected(const PageNumber&); - -private slots: - void showPopupMenu(const PageNumber& pageNumber, const TQPoint& position); - - void selectAll(); - void selectEven(); - void selectOdd(); - void toggleSelection(); - void removeSelection(); - -private: - TQPtrVector widgetList; - - PageNumber currentPage; - - PageNumber clickedThumbnail; - - DocumentPageCache* pageCache; - - bool showThumbnails; - - TDEPopupMenu* contextMenu; -}; - -#endif diff --git a/kviewshell/martdelist.cpp b/kviewshell/martdelist.cpp new file mode 100644 index 00000000..1cbf6581 --- /dev/null +++ b/kviewshell/martdelist.cpp @@ -0,0 +1,616 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Wilfried Huss + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "documentPageCache.h" +#include "kvsprefs.h" +#include "marklist.h" + + +#include "marklist.moc" + + +namespace { + +/** Holds the icon used as a overlay on pages which are not drawn yet. */ +TQPixmap* waitIcon = 0; + +} // namespace anon + + +/****** ThumbnailWidget ******/ + +ThumbnailWidget::ThumbnailWidget(MarkListWidget* _parent, const PageNumber& _pageNumber, DocumentPageCache* _pageCache) + : TQWidget(_parent), pageNumber(_pageNumber), pageCache(_pageCache), parent(_parent) +{ + setBackgroundMode(TQt::NoBackground); + + needsUpdating = true; + + if (!waitIcon) + { + waitIcon = new TQPixmap(TDEGlobal::iconLoader()->loadIcon("gear", KIcon::NoGroup, KIcon::SizeMedium)); + } +} + +void ThumbnailWidget::paintEvent(TQPaintEvent* e) +{ + // Only repaint if the widget is really visible. We need to check this because TQt + // sends paintEvents to all widgets that have ever been visible in the Scrollview + // whenever the ScrollView is resized. This also increases the percieved performance + // only thumbnails that are really needed are rendered. + if (!parent->isVisible()) + { + //kdDebug() << "Abort Thumbnail drawing for page " << pageNumber << endl; + return; + } + + TQPainter p(this); + p.setClipRect(e->rect()); + + // Paint a black border around the widget + p.setRasterOp(TQt::CopyROP); + p.setBrush(NoBrush); + p.setPen(TQt::black); + p.drawRect(rect()); + + // Remove 1 pixel from all sides of the rectangle, to eliminate overdraw with + // the black border. + TQRect thumbRect = rect(); + thumbRect.addCoords(1,1,-1,-1); + + // If the thumbnail is empty or has been marked for updating generate a new thumbnail. + if (thumbnail.isNull() || needsUpdating) + { + if (KVSPrefs::changeColors() && KVSPrefs::renderMode() == KVSPrefs::EnumRenderMode::Paper) + p.fillRect(thumbRect, KVSPrefs::paperColor()); + else + p.fillRect(thumbRect, TQt::white); + + // Draw busy indicator. + // Im not really sure if this is a good idea. + // While it is nice to see an indication that something is happening for pages which + // take long to redraw, it gets quite annoing for fast redraws. + // TODO: Disable or find something less distractiong. + p.drawPixmap(10, 10, *waitIcon); + + TQTimer::singleShot(50, this, TQT_SLOT(setThumbnail())); + return; + } + + // Safety check + if (thumbnail.isNull()) + { + kdDebug(1223) << "No Thumbnail for page " << pageNumber << " created." << endl; + return; + } + + + // The actual page starts at point (1,1) because of the outline. + // Therefore we need to shift the destination rectangle. + TQRect pixmapRect = thumbRect; + pixmapRect.moveBy(-1,-1); + + // Paint widget + bitBlt (this, thumbRect.topLeft(), &thumbnail, pixmapRect, CopyROP); +} + +void ThumbnailWidget::resizeEvent(TQResizeEvent*) +{ + thumbnail.resize(width(), height()); + // Generate a new thumbnail in the next paintEvent. + needsUpdating = true; +} + +void ThumbnailWidget::setThumbnail() +{ + if (!parent->isVisible()) + { + // We only want to calculate the thumbnail for widgets that are currently visible. + // When we are fast scrolling thru the document. Many paint events are created, that + // are often not needed anymore at the time the eventloop executes them. + //kdDebug() << "Delayed request Abort Thumbnail drawing for page " << pageNumber << endl; + kapp->processEvents(); + return; + } + + needsUpdating = false; + + // Draw Thumbnail + thumbnail = pageCache->createThumbnail(pageNumber, width() - 2); + + if (thumbnail.height() != height() + 2) + setFixedHeight(thumbnail.height() + 2); + + update(); + kapp->processEvents(); +} + + +/****** MarkListWidget ******/ + + +MarkListWidget::MarkListWidget(TQWidget* _parent, MarkList* _markList, const PageNumber& _pageNumber, + DocumentPageCache* _pageCache, bool _showThumbnail) + : TQWidget(_parent), showThumbnail(_showThumbnail), pageNumber(_pageNumber), + pageCache(_pageCache), markList(_markList) +{ + TQBoxLayout* layout = new TQVBoxLayout(this, margin); + + thumbnailWidget = 0; + if (showThumbnail) + { + thumbnailWidget = new ThumbnailWidget(this, pageNumber, pageCache); + layout->addWidget(thumbnailWidget, 1, TQt::AlignTop); + } + + TQBoxLayout* bottomLayout = new TQHBoxLayout(layout); + + checkBox = new TQCheckBox(TQString(), this ); + checkBox->setFocusPolicy(TQ_NoFocus); + TQToolTip::add(checkBox, i18n("Select for printing")); + bottomLayout->addWidget(checkBox, 0, TQt::AlignAuto); + + pageLabel = new TQLabel(TQString("%1").arg(pageNumber), this); + bottomLayout->addWidget(pageLabel, 1); + + _backgroundColor = TDEGlobalSettings::baseColor(); + + // Alternate between colors. + if ((pageNumber % 2 == 0) && TDEGlobalSettings::alternateBackgroundColor().isValid()) + _backgroundColor = TDEGlobalSettings::alternateBackgroundColor(); + + setPaletteBackgroundColor( _backgroundColor ); + + show(); +} + +bool MarkListWidget::isChecked() const +{ + return checkBox->isChecked(); +} + +void MarkListWidget::toggle() +{ + checkBox->toggle(); +} + +void MarkListWidget::setChecked( bool checked ) +{ + checkBox->setChecked(checked); +} + +void MarkListWidget::setSelected( bool selected ) +{ + if (selected) + setPaletteBackgroundColor( TQApplication::palette().active().highlight() ); + else + setPaletteBackgroundColor( _backgroundColor ); +} + +int MarkListWidget::setNewWidth(int width) +{ + int height = TQMAX(checkBox->height(), pageLabel->height()) + 2*margin; + if (showThumbnail) + { + // Calculate size of Thumbnail + int thumbnailWidth = TQMIN(width, KVSPrefs::maxThumbnailWidth()); + int thumbnailHeight = (int)((thumbnailWidth - 2*margin - 2) / pageCache->sizeOfPage(pageNumber).aspectRatio() + 0.5) + 2; + + // Resize Thumbnail if necessary + if (thumbnailWidget->size() != TQSize(thumbnailWidth, thumbnailHeight)) + thumbnailWidget->setFixedSize(thumbnailWidth - 2*margin, thumbnailHeight); + + height += thumbnailHeight + 2*margin; + } + + setFixedSize(width, height); + return height; +} + +bool MarkListWidget::isVisible() +{ + TQRect visibleRect(markList->contentsX(), markList->contentsY(), + markList->visibleWidth(), markList->visibleHeight()); + TQRect widgetRect(markList->childX(this), markList->childY(this), width(), height()); + + if (widgetRect.intersects(visibleRect)) + return true; + + return false; +} + + +void MarkListWidget::mousePressEvent(TQMouseEvent* e) +{ + // Select Page + if (e->button() == Qt::LeftButton) + { + emit selected(pageNumber); + } + else if (e->button() == Qt::RightButton) + { + emit showPopupMenu(pageNumber, e->globalPos()); + } +} + + +/****** MarkList ******/ + + +MarkList::MarkList(TQWidget* parent, const char* name) + : TQScrollView(parent, name), clickedThumbnail(0), showThumbnails(true), contextMenu(0) +{ + currentPage = PageNumber::invalidPage; + widgetList.setAutoDelete(true); + setFocusPolicy( TQ_StrongFocus ); + //viewport()->setFocusPolicy( TQ_WheelFocus ); + setResizePolicy(TQScrollView::Manual); + + setVScrollBarMode(TQScrollView::AlwaysOn); + setHScrollBarMode(TQScrollView::AlwaysOff); + + setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding); + + viewport()->setBackgroundMode(TQt::PaletteBase); + enableClipper(true); +} + +MarkList::~MarkList() +{ + delete contextMenu; +} + +void MarkList::setPageCache(DocumentPageCache* _pageCache) +{ + pageCache = _pageCache; +} + +TQValueList MarkList::selectedPages() const +{ + TQValueList list; + MarkListWidget* item; + for(unsigned int i = 0; i < widgetList.count(); i++) + { + item = widgetList[i]; + if (item->isChecked()) + list << (i + 1); + } + return list; +} + +void MarkList::setNumberOfPages(int numberOfPages, bool _showThumbnails) +{ + showThumbnails = _showThumbnails; + + widgetList.resize(numberOfPages); + + int y = 0; + + for (int page = 1; page <= numberOfPages; page++) + { + MarkListWidget* item = new MarkListWidget(viewport(), this, page, pageCache, showThumbnails); + + connect(item, TQT_SIGNAL(selected(const PageNumber&)), this, TQT_SLOT(thumbnailSelected(const PageNumber&))); + connect(item, TQT_SIGNAL(showPopupMenu(const PageNumber&, const TQPoint&)), this, TQT_SLOT(showPopupMenu(const PageNumber&, const TQPoint&))); + + widgetList.insert(page - 1, item); + + int height = item->setNewWidth(visibleWidth()); + addChild(item, 0, y); + + y += height; + } + resizeContents(visibleWidth(), y); + viewport()->update(); +} + +void MarkList::thumbnailSelected(const PageNumber& pageNumber) +{ + // This variable is set to remember that the next call to setCurrentPageNumber + // has been initiated with a left click on the thumbnail of page pageNumber. + clickedThumbnail = pageNumber; + emit selected(pageNumber); +} + +void MarkList::setCurrentPageNumber(const PageNumber& pageNumber) +{ + if (!pageNumber.isValid() || pageNumber > (int)widgetList.count()) + { + clickedThumbnail = 0; + return; + } + + if (currentPage == pageNumber) + return; + + MarkListWidget* item; + + // Clear old selection + if (currentPage.isValid() && currentPage <= (int)widgetList.count()) + { + item = widgetList[currentPage - 1]; + item->setSelected(false); + } + + // Draw new selection + item = widgetList[pageNumber - 1]; + item->setSelected(true); + + // Make selected page visible if the current page has not been set with a mouseclick + // in the thumbnail list. (We use this because it is a bit confusing if the element that + // you have just clicked on, is scrolled away under the mouse cursor) + if (clickedThumbnail != pageNumber) + ensureVisible(childX(item), childY(item), 0, item->height()); + + clickedThumbnail = 0; + + currentPage = pageNumber; +} + +void MarkList::clear() +{ + currentPage = PageNumber::invalidPage; + widgetList.resize(0); +} + +void MarkList::selectAll() +{ + MarkListWidget* item; + for (unsigned int i = 0; i < widgetList.count(); i++) + { + item = widgetList[i]; + item->setChecked(true); + } +} + +void MarkList::selectEven() +{ + MarkListWidget* item; + for (unsigned int i = 1; i < widgetList.count(); i = i + 2) + { + item = widgetList[i]; + item->setChecked(true); + } +} + +void MarkList::selectOdd() +{ + MarkListWidget* item; + for (unsigned int i = 0; i < widgetList.count(); i = i + 2) + { + item = widgetList[i]; + item->setChecked(true); + } +} + +void MarkList::toggleSelection() +{ + MarkListWidget* item; + for (unsigned int i = 0; i < widgetList.count(); i++) + { + item = widgetList[i]; + item->toggle(); + } +} + +void MarkList::removeSelection() +{ + MarkListWidget* item; + for (unsigned int i = 0; i < widgetList.count(); i++) + { + item = widgetList[i]; + item->setChecked(false); + } +} + +void MarkList::viewportResizeEvent(TQResizeEvent*) +{ + MarkListWidget* item; + + int yold = contentsHeight(); + int y = 0; + + for (unsigned int i = 0; i < widgetList.count(); i++) + { + item = widgetList[i]; + int height = item->setNewWidth(visibleWidth()); + moveChild(item, 0, y); + + y += height; + } + resizeContents(visibleWidth(), y); + + // If the height of the content has changed + if (yold != contentsHeight()) + { + // Make sure the selected item is still visible. + if (currentPage.isValid() && currentPage <= (int)widgetList.count()) + { + item = widgetList[currentPage-1]; + ensureVisible(childX(item), childY(item), 0, item->height()); + } + } + + viewport()->update(); +} + + +void MarkList::updateWidgetSize(const PageNumber& pageNumber) +{ + // safety checks + if (!pageNumber.isValid() || pageNumber > widgetList.count()) + { + kdError() << "MarkList::updateWidgetSize called with invalid pageNumber " << pageNumber << endl; + return; + } + + MarkListWidget* item; + + // Resize the changed widget + item = widgetList[pageNumber - 1]; + int height = item->setNewWidth(visibleWidth()); + int y = childY(item) + height; + + // Move the rest of the widgets + for (unsigned int i = pageNumber; i < widgetList.count(); i++) + { + item = widgetList[i]; + int height = item->height(); + moveChild(item, 0, y); + + y += height; + } + resizeContents(contentsWidth(), y); + + viewport()->update(); +} + +void MarkList::mousePressEvent(TQMouseEvent* e) +{ + if (e->button() == Qt::RightButton) + { + // We call showPopupMenu with an invalid pageNumber to indicate that + // the mouse does not point at a thumbnailWidget. + showPopupMenu(PageNumber::invalidPage, e->globalPos()); + } +} + +void MarkList::slotShowThumbnails(bool show) +{ + if (show != showThumbnails) + { + int numOfPages = widgetList.count(); + + if (numOfPages == 0) + return; + + // Save current page. + PageNumber _currentPage = currentPage; + + // Save page selections. + TQValueVector selections; + selections.resize(widgetList.count()); + for (unsigned int i = 0; i < widgetList.count(); i++) + selections[i] = widgetList[i]->isChecked(); + + // Rebuild thumbnail widgets. + clear(); + setNumberOfPages(numOfPages, show); + + // Restore current page. + setCurrentPageNumber(_currentPage); + + // Restore page selections + for (unsigned int i = 0; i < widgetList.count(); i++) + widgetList[i]->setChecked(selections[i]); + } +} + + +void MarkList::repaintThumbnails() +{ + bool show = showThumbnails; + int numOfPages = widgetList.count(); + + // Rebuild thumbnail widgets. + clear(); + setNumberOfPages(numOfPages, show); +} + + +void MarkList::showPopupMenu(const PageNumber& pageNumber, const TQPoint& position) +{ + if (contextMenu == 0) + { + // Initialize Contextmenu + contextMenu = new TDEPopupMenu(this, "markListContext"); + + contextMenu->insertItem(i18n("Select &Current Page"), 0); + contextMenu->insertItem(i18n("Select &All Pages"), 1); + contextMenu->insertItem(i18n("Select &Even Pages"), 2); + contextMenu->insertItem(i18n("Select &Odd Pages"), 3); + contextMenu->insertItem(i18n("&Invert Selection"), 4); + contextMenu->insertItem(i18n("&Deselect All Pages"), 5); + } + + if (widgetList.count() == 0) + { + for (int i = 0; i <= 5; i++) + contextMenu->setItemEnabled(i, false); + } + else + { + for (int i = 0; i <= 5; i++) + contextMenu->setItemEnabled(i, true); + } + + // Only allow to select the current page if we got a valid pageNumber. + if (pageNumber.isValid() && pageNumber <= (int)widgetList.count()) + contextMenu->setItemEnabled(0, true); + else + contextMenu->setItemEnabled(0, false); + + // Show Contextmenu + switch(contextMenu->exec(position)) + { + case 0: + widgetList[pageNumber - 1]->toggle(); + break; + + case 1: + selectAll(); + break; + + case 2: + selectEven(); + break; + + case 3: + selectOdd(); + break; + + case 4: + toggleSelection(); + break; + + case 5: + removeSelection(); + break; + } +} + diff --git a/kviewshell/martdelist.h b/kviewshell/martdelist.h new file mode 100644 index 00000000..0ee15758 --- /dev/null +++ b/kviewshell/martdelist.h @@ -0,0 +1,189 @@ +// -*- C++ -*- +/* This file is part of the KDE project + Copyright (C) 2004 Wilfried Huss + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef MARKLIST_H +#define MARKLIST_H + +#include "pageNumber.h" + +#include +#include +#include + +class TQCheckBox; +class TQLabel; +class TDEPopupMenu; + +class DocumentPageCache; + +class MarkList; +class MarkListWidget; + + +/****** ThumbnailWidget ******/ + + +class ThumbnailWidget : public TQWidget +{ + Q_OBJECT + + +public: + ThumbnailWidget(MarkListWidget* parent_, const PageNumber& _pageNumber, DocumentPageCache*); + +private: + virtual void paintEvent(TQPaintEvent*); + virtual void resizeEvent(TQResizeEvent*); + +private slots: + void setThumbnail(); + +private: + PageNumber pageNumber; + + bool needsUpdating; + + DocumentPageCache* pageCache; + + MarkListWidget* parent; + + TQPixmap thumbnail; +}; + + +/****** MarkListWidget ******/ + + +class MarkListWidget : public TQWidget +{ + Q_OBJECT + + +public: + MarkListWidget(TQWidget* _parent, MarkList*, const PageNumber& _pageNumber, DocumentPageCache*, bool _showThumbnail = true); + + bool isChecked() const; + + bool isVisible(); + +public slots: + void toggle(); + void setChecked( bool checked ); + + void setSelected( bool selected ); + + int setNewWidth(int width); + +signals: + /** Emitted when the Page is selected in the ThumbnailView. */ + void selected(const PageNumber&); + + /** Emitted on right click. */ + void showPopupMenu(const PageNumber& pageNumber, const TQPoint& position); + +protected: + virtual void mousePressEvent(TQMouseEvent*); + +private: + + bool showThumbnail; + + ThumbnailWidget* thumbnailWidget; + TQCheckBox* checkBox; + TQLabel* pageLabel; + TQColor _backgroundColor; + + const PageNumber pageNumber; + + DocumentPageCache* pageCache; + + static const int margin = 5; + + MarkList* markList; +}; + + +/****** MarkList ******/ + + +class MarkList: public TQScrollView +{ + Q_OBJECT + + +public: + MarkList(TQWidget* parent = 0, const char* name = 0); + virtual ~MarkList(); + + void setPageCache(DocumentPageCache*); + + TQValueList selectedPages() const; + + PageNumber currentPageNumber() { return currentPage; } + + PageNumber numberOfPages() { return widgetList.count(); } + + virtual TQSize sizeHint() const { return TQSize(); } + +public slots: + void setNumberOfPages(int numberOfPages, bool showThumbnails = true); + + void thumbnailSelected(const PageNumber& pageNumber); + void setCurrentPageNumber(const PageNumber& pageNumber); + + void clear(); + + void slotShowThumbnails(bool); + void repaintThumbnails(); + + void updateWidgetSize(const PageNumber&); + +protected: + virtual void viewportResizeEvent(TQResizeEvent*); + + virtual void mousePressEvent(TQMouseEvent*); + +signals: + void selected(const PageNumber&); + +private slots: + void showPopupMenu(const PageNumber& pageNumber, const TQPoint& position); + + void selectAll(); + void selectEven(); + void selectOdd(); + void toggleSelection(); + void removeSelection(); + +private: + TQPtrVector widgetList; + + PageNumber currentPage; + + PageNumber clickedThumbnail; + + DocumentPageCache* pageCache; + + bool showThumbnails; + + TDEPopupMenu* contextMenu; +}; + +#endif -- cgit v1.2.1