ScrollableImageCache.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef SCROLLABLE_IMAGE_CACHE_H
16 #define SCROLLABLE_IMAGE_CACHE_H
17 
18 #include "base/BaseTypes.h"
19 
20 #include "LayerGeometryProvider.h"
21 
22 #include <QImage>
23 #include <QRect>
24 #include <QPainter>
25 
38 {
39 public:
41  m_validLeft(0),
42  m_validWidth(0),
43  m_startFrame(0)
44  {}
45 
46  void invalidate() {
47  m_validWidth = 0;
48  }
49 
50  bool isValid() const {
51  return m_validWidth > 0;
52  }
53 
54  QSize getSize() const {
55  return m_image.size();
56  }
57 
62  void resize(QSize newSize) {
63  if (getSize() != newSize) {
64  m_image = QImage(newSize, QImage::Format_ARGB32_Premultiplied);
65  invalidate();
66  }
67  }
68 
69  int getValidLeft() const {
70  return m_validLeft;
71  }
72 
73  int getValidWidth() const {
74  return m_validWidth;
75  }
76 
77  int getValidRight() const {
78  return m_validLeft + m_validWidth;
79  }
80 
81  QRect getValidArea() const {
82  return QRect(m_validLeft, 0, m_validWidth, m_image.height());
83  }
84 
85  ZoomLevel getZoomLevel() const {
86  return m_zoomLevel;
87  }
88 
95  void setZoomLevel(ZoomLevel zoom) {
96  using namespace std::rel_ops;
97  if (m_zoomLevel != zoom) {
98  m_zoomLevel = zoom;
99  invalidate();
100  }
101  }
102 
103  sv_frame_t getStartFrame() const {
104  return m_startFrame;
105  }
106 
113  void setStartFrame(sv_frame_t frame) {
114  if (m_startFrame != frame) {
115  m_startFrame = frame;
116  invalidate();
117  }
118  }
119 
120  const QImage &getImage() const {
121  return m_image;
122  }
123 
130  void scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame);
131 
139  void adjustToTouchValidArea(int &left, int &width,
140  bool &isLeftOfValidArea) const;
141 
149  void drawImage(int left,
150  int width,
151  QImage image,
152  int imageLeft,
153  int imageWidth);
154 
155 private:
156  QImage m_image;
159  sv_frame_t m_startFrame;
160  ZoomLevel m_zoomLevel;
161 };
162 
163 #endif
void setZoomLevel(ZoomLevel zoom)
Set the zoom level.
ZoomLevel getZoomLevel() const
sv_frame_t getStartFrame() const
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
const QImage & getImage() const
void drawImage(int left, int width, QImage image, int imageLeft, int imageWidth)
Draw from an image onto the cache.
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 wit...
void scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame)
Set the new start frame for the cache, according to the geometry of the supplied LayerGeometryProvide...
A cached image for a view that scrolls horizontally, such as a spectrogram.
void setStartFrame(sv_frame_t frame)
Set the start frame.
void resize(QSize newSize)
Set the size of the cache.