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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
/***************************************************************************
SignalWidget.h - Widget for displaying the signal
-------------------
begin : Sun Nov 12 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 SIGNAL_WIDGET_H
#define SIGNAL_WIDGET_H
#include "config.h"
#include "libkwavegui_export.h"
#include <QtGlobal>
#include <QGridLayout>
#include <QImage>
#include <QLabel>
#include <QList>
#include <QObject>
#include <QPainter>
#include <QPixmap>
#include <QPointer>
#include <QPolygon>
#include <QQueue>
#include <QSize>
#include <QTimer>
#include <QWidget>
#include "libkwave/PluginManager.h"
#include "libkwave/SignalManager.h"
#include "libkwave/String.h"
#include "libgui/SignalView.h"
class QContextMenuEvent;
class QPoint;
class QVBoxLayout;
class QWheelEvent;
namespace Kwave
{
class SignalManager;
class Track;
/**
* The SignalWidget class is responsible for displaying and managing the
* views that belong to a signal.
*/
class LIBKWAVEGUI_EXPORT SignalWidget: public QWidget,
public Kwave::ViewManager
{
Q_OBJECT
public:
/**
* Constructor
* @param parent parent widget
* @param signal_manager signal manager of the file context
* @param upper_dock layout of the upper docking area
* @param lower_dock layout of the lower docking area
*/
SignalWidget(QWidget *parent,
Kwave::SignalManager *signal_manager,
QVBoxLayout *upper_dock, QVBoxLayout *lower_dock);
/** Destructor */
~SignalWidget() override;
/**
* sets new zoom factor and offset
* @param zoom the new zoom factor in pixels/sample
* @param offset the index of the first visible sample
*/
void setZoomAndOffset(double zoom, sample_index_t offset);
/**
* Returns the x coordinate of an absolute pixel position to a relative
* coordinate within the viewport area (without controls)
*/
int mapToViewPort(const QPoint &pos) const;
/**
* Returns the width of the viewport with the signal (without
* controls)
* @return width of the signal area [pixels]
*/
int visibleWidth() const;
/**
* Insert a new signal view into this widget (or the upper/lower
* dock area.
* @param view the signal view, must not be a null pointer
* @param controls a widget with controls, optionally, can be null
*/
virtual void insertView(Kwave::SignalView *view, QWidget *controls)
override;
signals:
/** child views can connected to this signal to synchronize repaints */
void sigRepaint();
public slots:
/**
* can be called by views to request a repaint, synchronized and
* throttled through our repaint timer
*/
void requestRepaint(Kwave::SignalView *view);
/** forward a sigCommand to the next layer */
void forwardCommand(const QString &command);
protected slots:
/** Handler for context menus */
void contextMenuEvent(QContextMenuEvent *e) override;
private slots:
/**
* called when the repaint timer has elapsed, to refresh all views that
* have requested a repaint and are in the repaint queue
*/
void repaintTimerElapsed();
/**
* Connected to the signal's sigTrackInserted.
* @param index numeric index of the inserted track
* @param track reference to the inserted track
* @see Signal::sigTrackInserted
* @internal
*/
void slotTrackInserted(unsigned int index, Kwave::Track *track);
/**
* Connected to the signal's sigTrackDeleted.
* @param index numeric index of the deleted track
* @param track reference to the deleted track
* @see Signal::sigTrackInserted
* @internal
*/
void slotTrackDeleted(unsigned int index, Kwave::Track *track);
/** context menu: "edit/undo" */
void contextMenuEditUndo() { forwardCommand(_("undo()")); }
/** context menu: "edit/redo" */
void contextMenuEditRedo() { forwardCommand(_("redo()")); }
/** context menu: "edit/cut" */
void contextMenuEditCut() { forwardCommand(_("cut()")); }
/** context menu: "edit/copy" */
void contextMenuEditCopy() { forwardCommand(_("copy()")); }
/** context menu: "edit/paste" */
void contextMenuEditPaste() {forwardCommand(_("paste()")); }
/** context menu: "save selection" */
void contextMenuSaveSelection() {
forwardCommand(_("saveselect()"));
}
/** context menu: "expand to labels" */
void contextMenuSelectionExpandToLabels() {
forwardCommand(_("expandtolabel()"));
}
/** context menu: "select next labels" */
void contextMenuSelectionNextLabels() {
forwardCommand(_("selectnextlabels()"));
}
/** context menu: "select previous labels" */
void contextMenuSelectionPrevLabels() {
forwardCommand(_("selectprevlabels()"));
}
/**
* updates the minimum height of the widget
* according to the number of rows
*/
void updateMinimumHeight();
signals:
/**
* Emits the offset and length of the current selection and the
* sample rate for converting it into milliseconds
* @param offset index of the first selected sample
* @param length number of selected samples
* @param rate sample rate
*/
void selectedTimeInfo(sample_index_t offset, sample_index_t length,
double rate);
/**
* Emits a command to be processed by the next higher instance.
*/
void sigCommand(const QString &command);
/** emitted to request update of the cursor */
void sigCursorChanged(sample_index_t pos);
protected:
/** slot for mouse wheel events, used for vertical zoom */
void wheelEvent(QWheelEvent *event) override;
private:
/** propagates the vertical zoom to all views */
void setVerticalZoom(double zoom);
/**
* insert a row in the m_layout, shifting all following rows to
* the end by one
* @param index the index if the row
* @param view a view widget, must not be null
* @param controls a widget with controls, can be null
*/
void insertRow(int index, Kwave::SignalView *view, QWidget *controls);
/**
* delete a row in the m_layout, shifting all following rows back to
* the start by one
* @param index the index if the row
*/
void deleteRow(int index);
private:
/** the signal manager of the corresponding context */
Kwave::SignalManager *m_signal_manager;
/**
* list of signal views. Contains one entry for each signal view,
* starting with the ones in m_upper_dock, then the ones in m_layout,
* and at the end the ones from m_lower_dock.
* The list is sorted in the order of the appearance in the GUI.
*/
QList< QPointer<Kwave::SignalView> > m_views;
/** the central layout with the views */
QGridLayout m_layout;
/** layout of the upper docking area */
QPointer<QVBoxLayout> m_upper_dock;
/** layout of the lower docking area */
QPointer<QVBoxLayout> m_lower_dock;
/**
* Offset from which signal is being displayed. This is equal to
* the index of the first visible sample.
*/
sample_index_t m_offset;
/** number of samples per pixel */
double m_zoom;
/** vertical zoom factor */
double m_vertical_zoom;
/** timer for limiting the number of repaints per second */
QTimer m_repaint_timer;
/** queue with pointers to all signal views that need a repaint */
QQueue< QPointer<Kwave::SignalView> > m_repaint_queue;
};
}
#endif /* SIGNAL_WIDGET_H */
//***************************************************************************
//***************************************************************************
|