1 /*************************************************************************** 2 SonagramWindow.h - window for showing a sonagram 3 ------------------- 4 begin : Fri Jul 28 2000 5 copyright : (C) 2000 by Thomas Eschenbacher 6 email : Thomas.Eschenbacher@gmx.de 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef SONAGRAM_WINDOW_H 19 #define SONAGRAM_WINDOW_H 20 21 #include "config.h" 22 23 #include <QTimer> 24 25 #include <KMainWindow> 26 27 class QBitmap; 28 class QImage; 29 30 /** height of the overview widget in a sonagram window [pixels] */ 31 #define SONAGRAM_OVERVIEW_HEIGHT 30 32 33 namespace Kwave 34 { 35 36 class ImageView; 37 class ScaleWidget; 38 39 /** 40 * Window for displaying a sonagram with scale, status bar and 41 * a small menu. 42 */ 43 class SonagramWindow: public KMainWindow 44 { 45 Q_OBJECT 46 47 public: 48 49 /** 50 * Constructor. 51 * @param parent the parent widget 52 * @param name reference to the initial name of the signal (used for 53 * setting the window title, might be an empty string) 54 */ 55 SonagramWindow(QWidget *parent, const QString &name); 56 57 /** 58 * Destructor. 59 */ 60 virtual ~SonagramWindow(); 61 62 /** 63 * Sets a new sonagram image to display. 64 * @param image the bitmap with the sonagram 65 */ 66 void setImage(QImage image); 67 68 /** 69 * Sets a new overview bitmap for the signal space 70 */ 71 void setOverView(const QImage &image); 72 73 /** 74 * Inserts a slice into the current image. If the slice contains more 75 * data than fits into the image, the remaining rest will be ignored, 76 * if less data is present, it will be filled with 0xFF. The previous 77 * content of the image slice will be cleared or updated in all cases. 78 * @param slice_nr index of the slice (horizontal position) [0..n-1] 79 * @param slice array with the byte data 80 */ 81 void insertSlice(const unsigned int slice_nr, const QByteArray &slice); 82 83 public slots: 84 85 /** closes the sonagram window */ 86 void close(); 87 88 /** not implemented yet */ 89 void save(); 90 91 /** not implemented yet */ 92 void load(); 93 94 /** not implemented yet */ 95 void toSignal(); 96 97 /** 98 * Sets the name of the signal / title of the window 99 * @param name the name of the signal 100 */ 101 void setName(const QString &name); 102 103 /** 104 * Sets a new color mode. If the mode is different from the current 105 * one, the image will be automatically refreshed. 106 */ 107 void setColorMode(int mode); 108 109 /** 110 * Used to update the display of the current position of the cursor. 111 * Position is given in coordinates of the QImage. 112 * @param pos current cursor position 113 */ 114 void cursorPosChanged(const QPoint pos); 115 116 /** 117 * sets information about the number of fft points (needed 118 * for translating cursor coordinates into time) 119 * @param points the number of fft points [1...] 120 */ 121 void setPoints(unsigned int points); 122 123 /** 124 * sets information about the sample rate (needed for 125 * translating cursor coordinates into time 126 * @param rate sample rate in samples per second 127 */ 128 void setRate(double rate); 129 130 private slots: 131 132 /** refreshes the image, connected to m_refresh_timer */ 133 void refresh_view(); 134 135 protected: 136 137 /** updates the scale widgets */ 138 void updateScaleWidgets(); 139 140 /** 141 * adjust the brightness so that the color space is optimally 142 * used and the user doesn't just see a white image 143 */ 144 void adjustBrightness(); 145 146 /** 147 * Translates pixel coordinates relative to the lower left corner 148 * of the QImage into time and frequency coordinates of the signal. 149 * This requires a valid sample rate to be set, otherwise the 150 * time coordinate will be returned as zero. 151 * @param p a QPoint with the pixel position, upper left is 0/0 152 * @param ms pointer to a double that receives the time coordinate 153 * in milliseconds (can be 0 to ignore) 154 * @param f pointer to a double that receives the frequency 155 * coordinate (can be 0 to ignore) 156 */ 157 void translatePixels2TF(const QPoint p, double *ms, double *f); 158 159 private: 160 161 /** status bar label for time */ 162 QLabel *m_status_time; 163 164 /** status bar label for frequency */ 165 QLabel *m_status_freq; 166 167 /** status bar label for amplitude */ 168 QLabel *m_status_ampl; 169 170 /** the QImage to be displayed */ 171 QImage m_image; 172 173 /** 174 * the color mode to be used. Currently only 0 (black/white) 175 * and 1 (rainbow colors) are used. 176 */ 177 int m_color_mode; 178 179 /** an ImageView to display the m_image and fit it into our window */ 180 Kwave::ImageView *m_view; 181 182 /** short overview over the signal */ 183 Kwave::ImageView *m_overview; 184 185 /** number of fft points */ 186 unsigned int m_points; 187 188 /** sample rate, needed for translating pixel coordinates */ 189 double m_rate; 190 191 /** widget for the scale on the time (x) axis */ 192 Kwave::ScaleWidget *m_xscale; 193 194 /** widget for the scale on the frequency (y) axis */ 195 Kwave::ScaleWidget *m_yscale; 196 197 /** timer used for refreshing the view from time to time */ 198 QTimer m_refresh_timer; 199 200 /** histogram of color indices, used for auto-contrast */ 201 unsigned int m_histogram[256]; 202 203 }; 204 } 205 206 #endif // _SONOGRAM_WINDOW_H_ 207 208 //*************************************************************************** 209 //*************************************************************************** 210