Commit 87131472 authored by Enrico Ros's avatar Enrico Ros
Browse files

Speed up in creation/deletion drawing by removing the child label widget.

Text drawing is done by hand.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=347251
parent 83310740
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
#include "page.h" #include "page.h"
Thumbnail::Thumbnail( QWidget *parent, const KPDFPage *page ) Thumbnail::Thumbnail( QWidget *parent, const KPDFPage *page )
: QWidget( parent ), m_page( page ), m_previewWidth( 0 ), m_previewHeight( 0 ) : QWidget( parent ), m_page( page ), m_previewWidth( 0 ), m_previewHeight( 0 ), m_selected( false )
{ {
m_label = new QLabel( QString::number( page->number() + 1 ), this ); m_labelNumber = page->number() + 1;
m_label->setAlignment( AlignCenter );
setPaletteBackgroundColor( palette().active().base() ); setPaletteBackgroundColor( palette().active().base() );
} }
...@@ -32,11 +31,11 @@ int Thumbnail::setThumbnailWidth( int width ) ...@@ -32,11 +31,11 @@ int Thumbnail::setThumbnailWidth( int width )
m_previewHeight = (int)(m_page->ratio() * width); m_previewHeight = (int)(m_page->ratio() * width);
// reposition label at bottom // reposition label at bottom
int labelHeight = m_label->sizeHint().height(); m_labelHeight = QFontMetrics( font() ).height();
m_label->setGeometry( 0, m_previewHeight + 3, width, labelHeight ); m_labelWidth = width;
// resize the widget // resize the widget
int totalHeight = m_previewHeight + 3 + labelHeight; int totalHeight = m_previewHeight + 3 + m_labelHeight;
resize( width, totalHeight ); resize( width, totalHeight );
// return this->height plus a little (4px) margin to the next page // return this->height plus a little (4px) margin to the next page
...@@ -45,9 +44,8 @@ int Thumbnail::setThumbnailWidth( int width ) ...@@ -45,9 +44,8 @@ int Thumbnail::setThumbnailWidth( int width )
void Thumbnail::setSelected( bool selected ) void Thumbnail::setSelected( bool selected )
{ {
// alternate 'base' or 'hilight' colors to represent selection m_selected = selected;
if (selected) m_label->setPaletteBackgroundColor( palette().active().highlight() ); update( 0, m_previewHeight + 3, m_labelWidth, m_labelHeight );
else m_label->setPaletteBackgroundColor( palette().active().base() );
} }
//END commands //END commands
...@@ -73,8 +71,12 @@ void Thumbnail::paintEvent( QPaintEvent * e ) ...@@ -73,8 +71,12 @@ void Thumbnail::paintEvent( QPaintEvent * e )
QRect clipRect = e->rect(); QRect clipRect = e->rect();
QPainter p( this ); QPainter p( this );
// draw the bottom label
QColor fillColor = m_selected ? palette().active().highlight() : palette().active().base();
p.fillRect( 0, m_previewHeight + 3, m_labelWidth, m_labelHeight, fillColor );
p.drawText( 0, m_previewHeight + 3, m_labelWidth, m_labelHeight, Qt::AlignCenter, QString::number( m_labelNumber ) );
// draw page outline // draw page outline
p.setPen( Qt::black );
p.drawRect( 0, 0, m_previewWidth + 2, m_previewHeight + 2 ); p.drawRect( 0, 0, m_previewWidth + 2, m_previewHeight + 2 );
p.setPen( Qt::gray ); p.setPen( Qt::gray );
p.drawLine( 4, m_previewHeight + 2, m_previewWidth + 2, m_previewHeight + 2 ); p.drawLine( 4, m_previewHeight + 2, m_previewWidth + 2, m_previewHeight + 2 );
......
...@@ -33,10 +33,13 @@ protected: ...@@ -33,10 +33,13 @@ protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
private: private:
QLabel *m_label;
const KPDFPage *m_page; const KPDFPage *m_page;
uint m_previewWidth; uint m_previewWidth;
uint m_previewHeight; uint m_previewHeight;
bool m_selected;
uint m_labelNumber;
uint m_labelHeight;
uint m_labelWidth;
}; };
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment