ScrollableImageCache Class Reference

A cached image for a view that scrolls horizontally, such as a spectrogram. More...

#include <ScrollableImageCache.h>

Public Member Functions

 ScrollableImageCache ()
 
void invalidate ()
 
bool isValid () const
 
QSize getSize () const
 
void resize (QSize newSize)
 Set the size of the cache. More...
 
int getValidLeft () const
 
int getValidWidth () const
 
int getValidRight () const
 
QRect getValidArea () const
 
ZoomLevel getZoomLevel () const
 
void setZoomLevel (ZoomLevel zoom)
 Set the zoom level. More...
 
sv_frame_t getStartFrame () const
 
void setStartFrame (sv_frame_t frame)
 Set the start frame. More...
 
const QImage & getImage () const
 
void scrollTo (const LayerGeometryProvider *v, sv_frame_t newStartFrame)
 Set the new start frame for the cache, according to the geometry of the supplied LayerGeometryProvider, if possible also moving along any existing valid data within the cache so that it continues to be valid for the new start frame. More...
 
void adjustToTouchValidArea (int &left, int &width, bool &isLeftOfValidArea) const
 Take a left coordinate and width describing a region, and adjust them so that they are contiguous with the cache valid region and so that the union of the adjusted region with the cache valid region contains the supplied region. More...
 
void drawImage (int left, int width, QImage image, int imageLeft, int imageWidth)
 Draw from an image onto the cache. More...
 

Private Attributes

QImage m_image
 
int m_validLeft
 
int m_validWidth
 
sv_frame_t m_startFrame
 
ZoomLevel m_zoomLevel
 

Detailed Description

A cached image for a view that scrolls horizontally, such as a spectrogram.

The cache object holds an image, reports the size of the image (likely the same as the underlying view, but it's the caller's responsibility to set the size appropriately), can scroll the image, and can report and update which contiguous horizontal range of the image is valid.

The only way to update the valid area in a cache is to draw to it using the drawImage call.

Definition at line 37 of file ScrollableImageCache.h.

Constructor & Destructor Documentation

ScrollableImageCache::ScrollableImageCache ( )
inline

Definition at line 40 of file ScrollableImageCache.h.

Member Function Documentation

void ScrollableImageCache::invalidate ( )
inline

Definition at line 46 of file ScrollableImageCache.h.

References m_validWidth.

Referenced by resize(), setStartFrame(), and setZoomLevel().

bool ScrollableImageCache::isValid ( ) const
inline

Definition at line 50 of file ScrollableImageCache.h.

References m_validWidth.

QSize ScrollableImageCache::getSize ( ) const
inline

Definition at line 54 of file ScrollableImageCache.h.

References m_image.

Referenced by resize().

void ScrollableImageCache::resize ( QSize  newSize)
inline

Set the size of the cache.

If the new size differs from the current size, the cache is invalidated.

Definition at line 62 of file ScrollableImageCache.h.

References getSize(), invalidate(), and m_image.

int ScrollableImageCache::getValidLeft ( ) const
inline

Definition at line 69 of file ScrollableImageCache.h.

References m_validLeft.

int ScrollableImageCache::getValidWidth ( ) const
inline

Definition at line 73 of file ScrollableImageCache.h.

References m_validWidth.

int ScrollableImageCache::getValidRight ( ) const
inline

Definition at line 77 of file ScrollableImageCache.h.

References m_validLeft, and m_validWidth.

QRect ScrollableImageCache::getValidArea ( ) const
inline

Definition at line 81 of file ScrollableImageCache.h.

References m_image, m_validLeft, and m_validWidth.

ZoomLevel ScrollableImageCache::getZoomLevel ( ) const
inline

Definition at line 85 of file ScrollableImageCache.h.

References m_zoomLevel.

void ScrollableImageCache::setZoomLevel ( ZoomLevel  zoom)
inline

Set the zoom level.

If the new zoom level differs from the current one, the cache is invalidated. (Determining whether to invalidate the cache here is the only thing the zoom level is used for.)

Definition at line 95 of file ScrollableImageCache.h.

References invalidate(), and m_zoomLevel.

sv_frame_t ScrollableImageCache::getStartFrame ( ) const
inline

Definition at line 103 of file ScrollableImageCache.h.

References m_startFrame.

void ScrollableImageCache::setStartFrame ( sv_frame_t  frame)
inline

Set the start frame.

If the new start frame differs from the current one, the cache is invalidated. To scroll, i.e. to set the start frame while retaining cache validity where possible, use scrollTo() instead.

Definition at line 113 of file ScrollableImageCache.h.

References invalidate(), and m_startFrame.

const QImage& ScrollableImageCache::getImage ( ) const
inline

Definition at line 120 of file ScrollableImageCache.h.

References adjustToTouchValidArea(), drawImage(), m_image, and scrollTo().

void ScrollableImageCache::scrollTo ( const LayerGeometryProvider v,
sv_frame_t  newStartFrame 
)

Set the new start frame for the cache, according to the geometry of the supplied LayerGeometryProvider, if possible also moving along any existing valid data within the cache so that it continues to be valid for the new start frame.

Definition at line 25 of file ScrollableImageCache.cpp.

References LayerGeometryProvider::getXForFrame().

Referenced by getImage().

void ScrollableImageCache::adjustToTouchValidArea ( int &  left,
int &  width,
bool &  isLeftOfValidArea 
) const

Take a left coordinate and width describing a region, and adjust them so that they are contiguous with the cache valid region and so that the union of the adjusted region with the cache valid region contains the supplied region.

Does not modify anything about the cache, only about the arguments.

Definition at line 114 of file ScrollableImageCache.cpp.

Referenced by getImage().

void ScrollableImageCache::drawImage ( int  left,
int  width,
QImage  image,
int  imageLeft,
int  imageWidth 
)

Draw from an image onto the cache.

The supplied image must have the same height as the cache and the full height is always drawn. The left and width parameters determine the target region of the cache, the imageLeft and imageWidth parameters the source region of the image.

Definition at line 143 of file ScrollableImageCache.cpp.

Referenced by getImage().

Member Data Documentation

QImage ScrollableImageCache::m_image
private

Definition at line 156 of file ScrollableImageCache.h.

Referenced by getImage(), getSize(), getValidArea(), and resize().

int ScrollableImageCache::m_validLeft
private

Definition at line 157 of file ScrollableImageCache.h.

Referenced by getValidArea(), getValidLeft(), and getValidRight().

int ScrollableImageCache::m_validWidth
private
sv_frame_t ScrollableImageCache::m_startFrame
private

Definition at line 159 of file ScrollableImageCache.h.

Referenced by getStartFrame(), and setStartFrame().

ZoomLevel ScrollableImageCache::m_zoomLevel
private

Definition at line 160 of file ScrollableImageCache.h.

Referenced by getZoomLevel(), and setZoomLevel().


The documentation for this class was generated from the following files: