video_cheatsheet.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
51 #include "video_cheatsheet.h"
52 
53 #include <QtWidgets>
54 #include <QVideoWidget>
55 #include <QDebug>
56 #include <QSize>
57 
58 HelpVideo::HelpVideo(QWidget *parent)
59  : QDialog(parent)
60 {
61  setWindowTitle("Cheatsheet");
62  _media_player = new QMediaPlayer(this, QMediaPlayer::VideoSurface);
63  QVideoWidget *videoWidget = new QVideoWidget;
64 
65  videoWidget->setAutoFillBackground(true);
66  auto palette = videoWidget->palette();
67  palette.setColor( QPalette::Window, Qt::white);
68  videoWidget->setPalette(palette);
69  videoWidget->setAttribute(Qt::WA_OpaquePaintEvent, true);
70 
71  _playlist = new QMediaPlaylist();
72  QListWidget* list_widget = new QListWidget();
73  _text = new QLabel("placeholder");
74 
75  _media_player->setPlaylist(_playlist);
76 
77  _playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
78 
79  list_widget->setSelectionMode(QAbstractItemView::SingleSelection);
80 
81  _text->setFixedWidth(600);
82 
83  videoWidget->setFixedSize( QSize(900,600) );
84  list_widget->setMinimumWidth(200);
85 
86  QBoxLayout *videoLayout = new QVBoxLayout;
87 
88  videoLayout->setMargin(20);
89  videoLayout->setSpacing(20);
90  videoLayout->addWidget(_text);
91  videoLayout->addWidget(videoWidget);
92  videoLayout->addWidget(new QLabel("If you can't see the videos, install codecs with [sudo apt-get install libqt5multimedia5-plugins]"));
93 
94  videoLayout->setStretch(0,1);
95  videoLayout->setStretch(1,0);
96  videoLayout->setStretch(2,0);
97 
98  QBoxLayout *layout = new QHBoxLayout;
99  layout->addWidget(list_widget);
100  layout->addLayout(videoLayout);
101 
102  setLayout(layout);
103 
104  _media_player->setVideoOutput(videoWidget);
105 
106  connect(_media_player,
107  static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
108  this, &HelpVideo::handleError);
109 
110  setupHelps();
111 
112  for(const auto& section: _help_sections)
113  {
114  list_widget->addItem( section.title );
115  _playlist->addMedia( section.video_url );
116  }
117 
118  _text->setWordWrap(true);
119 
120  connect( list_widget, &QListWidget::currentRowChanged, this, [this](int row)
121  {
122  _playlist->setCurrentIndex(row);
123  QString label_text = QString("<h2>%1</h2>%2").arg(_help_sections[row].title, _help_sections[row].text);
124  _text->setText( label_text );
125  _media_player->play();
126  });
127 
128  list_widget->item(0)->setSelected(true);
129 }
130 
132 {
133 }
134 
135 
137 {
138  _help_sections.push_back( {"Add timeseries to plot",
139  "Drag and Drop timeseries from the the list on the left side"
140  " using the <b>Left Mouse</b> button.",
141  QUrl("qrc:/cheatsheet/video/cheatsheet-drag-drop.mp4")});
142 
143  _help_sections.push_back( {"Create XY plots",
144  "Using two timeseries, sharing the same time axis, it is possible"
145  " to create a XY plot. Drag and Drop the Y axis as usual, using the"
146  " <b>Left Mouse</b> and the X axis with the <b>Right Mouse</b>.",
147  QUrl("qrc:/cheatsheet/video/cheatsheet-xy.mp4")});
148 
149  _help_sections.push_back( {"Pan view",
150  "To pan the plot area, either use the <b>Middle Mouse</b> button or"
151  " <b>CTRL + Left Mouse</b>.",
152  QUrl("qrc:/cheatsheet/video/cheatsheet-pan-view.mp4")});
153 
154  _help_sections.push_back( {"Remove Columns/Rows",
155  "To remove entire columns or/and rows, you must first clear all the curves.",
156  QUrl("qrc:/cheatsheet/video/cheatsheet-remove-column.mp4")});
157 
158  _help_sections.push_back( {"Resize Fonts",
159  "To change the size of the fonts used in the legend or the list of timeseries"
160  " on the left side, use <b>CTRL + Mouse Wheel</b>",
161  QUrl("qrc:/cheatsheet/video/cheatsheet-resize-font.mp4")});
162 
163  _help_sections.push_back( {"Swap Plots",
164  "Swap two plots using <b>CTRL + Right Mouse</b>.",
165  QUrl("qrc:/cheatsheet/video/cheatsheet-swap.mp4")});
166 
167  _help_sections.push_back( {"Time tracker",
168  "The time tracker is a vertical line that is helpful to visualize the"
169  " value of the timeseries at a given time.<br>"
170  "Furthermore, it is connected to the Publishers plugins: every time the time"
171  " tracker is activated, all the active publisher are called."
172  " Move the tracker either using the <b>Slider</b> at the bottom or pressing"
173  "<b> SHIFT + Left Mouse</b>.",
174  QUrl("qrc:/cheatsheet/video/cheatsheet-tracker.mp4")});
175 
176 
177  _help_sections.push_back( {"Zoom Area",
178  "Click with the <b>Left Mouse</b> button on the plot area"
179  " and select the rectangle to zoom in.",
180  QUrl("qrc:/cheatsheet/video/cheatsheet-zoom-area.mp4")});
181 
182  _help_sections.push_back( {"Zoom In and Out",
183  "Use the <b>Mouse Wheel</b> to zoom in or out.<br>"
184  "Additionally, you can zoom a single axis moving the mouse cursor"
185  " either on the bottom X scale (<b>zoom horizontally only</b>) or on the left"
186  " Y scale (<b>zoom vertically only</b>).",
187  QUrl("qrc:/cheatsheet/video/cheatsheet-zoom-in-out.mp4")});
188 }
189 
190 
191 
192 void HelpVideo::handleError(QMediaPlayer::Error)
193 {
194 
195  const QString errorString = _media_player->errorString();
196  QString message = "Error: ";
197  if (errorString.isEmpty())
198  message += " #" + QString::number(int(_media_player->error()));
199  else
200  message += errorString;
201  qDebug() << message;
202 }
QLabel * _text
HelpVideo(QWidget *parent=nullptr)
std::vector< HelpSection > _help_sections
void handleError(QMediaPlayer::Error)
QMediaPlayer * _media_player
QMediaPlaylist * _playlist


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18