File: OverViewWidget.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (236 lines) | stat: -rw-r--r-- 7,531 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/***************************************************************************
       OverViewWidget.h  -  horizontal slider with overview over a signal
                             -------------------
    begin                : Tue Oct 21 2000
    copyright            : (C) 2000 by Thomas Eschenbacher
    email                : Thomas.Eschenbacher@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef OVER_VIEW_WIDGET_H
#define OVER_VIEW_WIDGET_H

#include "config.h"
#include "libkwavegui_export.h"

#include <QtGlobal>
#include <QBitmap>
#include <QColor>
#include <QSize>
#include <QThread>
#include <QTimer>
#include <QWidget>

#include "libkwave/LabelList.h"
#include "libkwave/MetaDataList.h"

#include "libgui/ImageView.h"
#include "libgui/OverViewCache.h"

class QMouseEvent;
class QPainter;
class QResizeEvent;

namespace Kwave
{

    class SignalManager;

    class LIBKWAVEGUI_EXPORT OverViewWidget: public Kwave::ImageView
    {
        Q_OBJECT
    public:
        /** Constructor */
        explicit OverViewWidget(Kwave::SignalManager &signal,
                                QWidget *parent = nullptr);

        /** Destructor */
        ~OverViewWidget() override;

        /** minimum size of the widget, @see QWidget::minimumSize() */
        virtual QSize minimumSize() const;

        /** optimal size for the widget, @see QWidget::sizeHint() */
        QSize sizeHint() const override;

    public slots:

        /**
         * Sets new range parameters of the slider, using a scale that is
         * calculated* out of the slider's maximum position. All parameters
         * are given in the user's coordinates/units (e.g. samples).
         * @param offset index of the first visible sample
         * @param viewport width of the visible area
         * @param total width of the whole signal
         */
        void setRange(sample_index_t offset, sample_index_t viewport,
                      sample_index_t total);

        /**
         * called when the selected time has changed
         * @param offset index of the first selected sample
         * @param length number of selected samples
         */
        void setSelection(sample_index_t offset, sample_index_t length);

        /**
        * should be called when meta data has changed
        * @param meta the list of new meta data
        */
        void metaDataChanged(Kwave::MetaDataList meta);

        /**
         * shows the cursor at a given position
         * @param pos current position of the cursor
         */
        void showCursor(sample_index_t pos = SAMPLE_INDEX_MAX);

    protected:

        /** refreshes the bitmap when resized */
        void resizeEvent(QResizeEvent *) override;

        /**
         * On mouse move:
         * move the current viewport center to the clicked position.
         */
        void mouseMoveEvent(QMouseEvent *) override;

        /**
         * On single-click with the left mouse button:
         * move the current viewport center to the clicked position.
         */
        void mousePressEvent(QMouseEvent *) override;

        /**
         * On double click with the left mouse button, without shift:
         * move the current viewport center to the clicked position, like
         * on a single-click, but also zoom in (by sending "view:zoom_in()").
         *
         * When double clicked with the left mouse button with shift:
         * The same as above, but zoom out instead of in
         * (by sending "view:zoom_out()").
         */
        void mouseDoubleClickEvent(QMouseEvent *e) override;

    protected slots:

        /** refreshes all modified parts of the bitmap */
        void refreshBitmap();

        /**
         * connected to the m_repaint_timer, called when it has
         * elapsed and the signal has to be repainted
         */
        void overviewChanged();

    signals:

        /**
         * Will be emitted if the slider position has changed. The value
         * is in user's units (e.g. samples).
         */
        void valueChanged(sample_index_t new_value);

        /** emitted for zooming in and out via command */
        void sigCommand(const QString &command);

        /** emitted when the background calculation of the image is done */
        void newImage(QImage image);

    protected:

        /**
         * Converts a pixel offset within the overview's drawing area
         * into the user's coordinate system.
         * @param pixels the pixel coordinate [0...width-1]
         * @return an offset [0..length-1]
         */
        sample_index_t pixels2offset(int pixels);

        /**
         * draws a little mark at the top and bottom of a line
         * in the overview image
         * @param p a QPainter used for painting, will be modified
         * @param x offset from the left [pixel]
         * @param height the height of the image [pixel]
         * @param color base color for the marker
         */
        void drawMark(QPainter &p, int x, int height, QColor color);

    private:

        /** does the calculation of the new bitmap in background */
        void calculateBitmap();

    private:

        /** internal worker thread for updating the bitmap in background */
        class WorkerThread: public QThread
        {
        public:
            /** constructor */
            explicit WorkerThread(Kwave::OverViewWidget *widget);

            /** destructor */
            ~WorkerThread() override;

            /** thread function that calls calculateBitmap() */
            void run() override;

        private:

            /** pointer to the calling overview widget */
            Kwave::OverViewWidget *m_overview;
        };

    private:

        /** index of the first visible sample */
        sample_index_t m_view_offset;

        /** width of the visible area [samples] */
        sample_index_t m_view_width;

        /** length of the whole area [samples] */
        sample_index_t m_signal_length;

        /** start of the selection [samples] */
        sample_index_t m_selection_start;

        /** length of the selection [samples] */
        sample_index_t m_selection_length;

        /** last cursor position */
        sample_index_t m_cursor_position;

        /** last emitted offset (for avoiding duplicate events) */
        sample_index_t m_last_offset;

        /** cache with overview data */
        Kwave::OverViewCache m_cache;

        /** timer for limiting the number of repaints per second */
        QTimer m_repaint_timer;

        /** list of labels */
        Kwave::LabelList m_labels;

        /** worker thread for updates in background */
        WorkerThread m_worker_thread;

    };
}

#endif // _OVER_VIEW_WIDGET_H_

//***************************************************************************
//***************************************************************************