kpixmapsplitter.cpp Source File (kdefx Library)

| # kdefx Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kpixmapsplitter.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public License
    00015     along with this library; see the file COPYING.LIB.  If not, write to
    00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    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         // qDebug("cols: %i, rows: %i (pixmap: %i, %i)", m_numCols, m_numRows, m_pixmap.width(), m_pixmap.height());
    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

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:44:24 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001