00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kpixmapsplitter.h"
00021
00022 KPixmapSplitter::KPixmapSplitter()
00023 : m_itemSize( 4, 7 ),
00024 m_vSpacing( 0 ),
00025 m_hSpacing( 0 ),
00026 m_numCols( 0 ),
00027 m_numRows( 0 ),
00028 m_dirty( false )
00029 {
00030 }
00031
00032 KPixmapSplitter::~KPixmapSplitter()
00033 {
00034 }
00035
00036 void KPixmapSplitter::setPixmap(
const QPixmap& pixmap )
00037 {
00038 m_pixmap = pixmap;
00039 m_dirty =
true;
00040 }
00041
00042 void KPixmapSplitter::setItemSize(
const QSize& size )
00043 {
00044
if ( size != m_itemSize ) {
00045 m_itemSize = size;
00046 m_dirty =
true;
00047 }
00048 }
00049
00050 void KPixmapSplitter::setVSpacing(
int spacing )
00051 {
00052
if ( spacing != m_vSpacing ) {
00053 m_vSpacing = spacing;
00054 m_dirty =
true;
00055 }
00056 }
00057
00058 void KPixmapSplitter::setHSpacing(
int spacing )
00059 {
00060
if ( spacing != m_hSpacing ) {
00061 m_hSpacing = spacing;
00062 m_dirty =
true;
00063 }
00064 }
00065
00066
00067 QRect KPixmapSplitter::coordinates(
int pos )
00068 {
00069
if ( pos < 0 || m_pixmap.
isNull() )
00070
return QRect();
00071
00072
if ( m_dirty ) {
00073 m_numCols = m_pixmap.
width() / ( m_itemSize.
width() + m_hSpacing );
00074 m_numRows = m_pixmap.
height() / ( m_itemSize.
height() + m_vSpacing );
00075 m_dirty =
false;
00076
00077 }
00078
00079
if ( m_numCols == 0 || m_numRows == 0 )
00080
return QRect();
00081
00082
int row = pos / m_numCols;
00083
int col = pos - (row * m_numCols);
00084
00085
return QRect( col * (m_itemSize.
width() + m_hSpacing),
00086 row * (m_itemSize.
height() + m_vSpacing),
00087 m_itemSize.
width(),
00088 m_itemSize.
height() );
00089 }
00090
00091 QRect KPixmapSplitter::coordinates(
const QChar& ch )
00092 {
00093
return coordinates( (
unsigned char) ch.
latin1() );
00094 }
00095