23 #include <QApplication> 25 #include <QContextMenuEvent> 26 #include <QDragEnterEvent> 27 #include <QDragLeaveEvent> 28 #include <QDragMoveEvent> 34 #include <QMouseEvent> 35 #include <QPaintEvent> 36 #include <QResizeEvent> 41 #include <KLocalizedString> 71 #define VERTICAL_ZOOM_MIN 1.0 74 #define VERTICAL_ZOOM_MAX 100.0 77 #define VERTICAL_ZOOM_STEP_FACTOR 1.5 80 #define REPAINT_INTERVAL 50 85 QVBoxLayout *upper_dock,
86 QVBoxLayout *lower_dock)
88 m_signal_manager(signal_manager),
91 m_upper_dock(upper_dock),
92 m_lower_dock(lower_dock),
121 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
139 Q_ASSERT(zoom >= 0.0);
140 foreach (QPointer<Kwave::SignalView> view,
m_views)
141 view->setZoomAndOffset(zoom, offset);
182 if (!have_signal)
return;
187 QMenu *context_menu =
new QMenu(
this);
188 Q_ASSERT(context_menu);
189 if (!context_menu)
return;
195 action = context_menu->addAction(
196 QIcon::fromTheme(
_(
"edit-undo")),
198 Qt::CTRL + Qt::Key_Z);
202 action->setEnabled(
false);
205 action = context_menu->addAction(
206 QIcon::fromTheme(
_(
"edit-redo")),
208 Qt::CTRL + Qt::Key_Y);
212 action->setEnabled(
false);
213 context_menu->addSeparator();
216 QAction *action_cut = context_menu->addAction(
217 QIcon::fromTheme(
_(
"edit-cut")),
219 Qt::CTRL + Qt::Key_X);
220 QAction *action_copy = context_menu->addAction(
221 QIcon::fromTheme(
_(
"edit-copy")),
223 Qt::CTRL + Qt::Key_C);
224 QAction *action_paste = context_menu->addAction(
225 QIcon::fromTheme(
_(
"edit-paste")),
227 Qt::CTRL + Qt::Key_V);
228 context_menu->addSeparator();
229 if (action_cut) action_cut->setEnabled(have_selection);
230 if (action_copy) action_copy->setEnabled(have_selection);
234 int mouse_x = mapFromGlobal(e->globalPos()).x();
235 int mouse_y = mapFromGlobal(e->globalPos()).y();
236 if (mouse_x < 0) mouse_x = 0;
237 if (mouse_y < 0) mouse_y = 0;
238 if (mouse_x >= width()) mouse_x = width() - 1;
239 if (mouse_y >= height()) mouse_y = height() - 1;
242 QMenu *submenu_select = context_menu->addMenu(i18n(
"Selection"));
243 Q_ASSERT(submenu_select);
244 if (!submenu_select)
return;
247 QAction *action_select_save = submenu_select->addAction(
248 QIcon::fromTheme(
_(
"document-save")),
250 Q_ASSERT(action_select_save);
251 if (!action_select_save)
return;
252 action_select_save->setEnabled(have_selection);
255 QAction *action_select_expand_to_labels = submenu_select->addAction(
256 i18n(
"&Expand to Labels"),
this,
258 Q_ASSERT(action_select_expand_to_labels);
259 if (!action_select_expand_to_labels)
return;
260 action_select_expand_to_labels->setEnabled(have_labels);
263 QAction *action_select_next_labels = submenu_select->addAction(
264 i18n(
"To Next Labels"),
this,
266 Qt::SHIFT + Qt::CTRL + Qt::Key_N);
267 Q_ASSERT(action_select_next_labels);
268 if (!action_select_next_labels)
return;
269 action_select_next_labels->setEnabled(have_labels);
272 QAction *action_select_prev_labels = submenu_select->addAction(
273 i18n(
"To Previous Labels"),
this,
275 Qt::SHIFT + Qt::CTRL + Qt::Key_P);
276 Q_ASSERT(action_select_prev_labels);
277 if (!action_select_prev_labels)
return;
278 action_select_prev_labels->setEnabled(have_labels);
281 QSharedPointer<Kwave::ViewItem> item(Q_NULLPTR);
282 foreach (QPointer<Kwave::SignalView> view,
m_views) {
284 const QRect view_rect = QRect(
285 view->mapToParent(view->rect().topLeft()),
286 view->mapToParent(view->rect().bottomRight()));
289 if (view_rect.contains(mouse_x, mouse_y)) {
291 QPoint pos = view->mapFromParent(QPoint(mouse_x, mouse_y));
294 view->handleContextMenu(pos, context_menu);
297 item = view->findItem(pos);
300 if (!item.isNull()) {
303 item->appendContextMenu(context_menu);
311 context_menu->exec(QCursor::pos());
321 if (event->modifiers() != Qt::AltModifier) {
326 if (event->delta() > 0) {
330 }
else if (event->delta() < 0) {
351 foreach (QPointer<Kwave::SignalView> view,
m_views)
355 foreach (QPointer<Kwave::SignalView> view,
m_views)
363 if (
m_views.isEmpty())
return mapFromGlobal(pos).x();
364 return mapFromGlobal(pos).x() -
m_layout.cellRect(0, 1).left();
370 if (
m_views.isEmpty())
return width();
371 return m_layout.cellRect(0, 1).width();
378 const int rows =
m_layout.rowCount();
379 const int cols =
m_layout.columnCount();
382 for (
int row = rows; row > index; row--) {
383 for (
int col = 0; col < cols; col++) {
384 QLayoutItem *item =
m_layout.itemAtPosition(row - 1, col);
397 m_layout.addWidget(controls, index, 0);
410 qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
411 QEventLoop::ExcludeSocketNotifiers);
418 const int rows =
m_layout.rowCount();
419 const int cols =
m_layout.columnCount();
425 for (
int row = index; row < (rows - 1); row++) {
426 for (
int col = 0; col < cols; col++) {
427 QLayoutItem *item =
m_layout.itemAtPosition(row + 1, col);
451 int track = (view) ? view->
track() : -1;
479 for (;index <
m_views.count(); ++row, ++index) {
480 if (
m_views[index]->track() >= track)
break;
481 if (
m_views[index]->preferredLocation() >=
491 for (;index <
m_views.count(); ++row, ++index) {
492 if (
m_views[index]->track() < track)
continue;
493 if (
m_views[index]->track() != track)
break;
494 if (
m_views[index]->preferredLocation() !=
504 for (;index <
m_views.count(); ++row, ++index) {
505 if (
m_views[index]->track() < track)
continue;
506 if (
m_views[index]->track() != track)
break;
507 if (
m_views[index]->preferredLocation() >=
517 for (;index <
m_views.count(); ++row, ++index) {
518 if (
m_views[index]->track() < track)
continue;
519 if (
m_views[index]->track() != track)
break;
520 if (
m_views[index]->preferredLocation() >=
550 Q_ASSERT(index >= 0);
551 Q_ASSERT(index < m_upper_dock->count() +
m_layout.rowCount() +
561 Qt::QueuedConnection);
566 connect(view, SIGNAL(contentSizeChanged()),
568 connect(view, SIGNAL(destroyed(QObject*)),
586 QWidget *controls =
new QWidget(Q_NULLPTR);
588 if (!controls)
return;
600 foreach (QPointer<Kwave::SignalView> view,
m_views) {
602 view->setTrack(view->track() + 1);
620 QMutableListIterator<QPointer<Kwave::SignalView> > it(
m_views);
621 while (it.hasNext()) {
629 }
else if (view->
track() != -1) {
635 const int rows =
m_layout.rowCount();
636 const int cols =
m_layout.columnCount();
637 for (
int row = 0; row < rows; row++) {
638 bool row_is_empty =
true;
639 for (
int col = 0; col < cols; col++) {
640 QLayoutItem *item =
m_layout.itemAtPosition(row, col);
642 row_is_empty =
false;
662 const int rows =
m_layout.rowCount();
663 const int cols =
m_layout.columnCount();
664 for (
int row = 0; row < rows; row++) {
666 for (
int col = 0; col < cols; col++) {
667 QLayoutItem *item =
m_layout.itemAtPosition(row, col);
668 QWidget *widget = (item) ? item->widget() : Q_NULLPTR;
670 int min_height = widget->minimumSize().height();
671 if (min_height > h) h = min_height;
676 if (rows > 1) height += (rows - 1) *
m_layout.verticalSpacing();
678 setMinimumHeight(height);
static ClipBoard & instance()
Kwave::MetaDataList & metaData()
virtual void addSibling(QWidget *widget)
Kwave::Selection & selection()
virtual void setVerticalZoom(double zoom)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
sample_index_t length() const
virtual void setTrack(int track)
virtual void setZoomAndOffset(double zoom, sample_index_t offset)
Location preferredLocation() const