video_cheatsheet.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2017 The Qt Company Ltd.
00004 ** Contact: https://www.qt.io/licensing/
00005 **
00006 ** This file is part of the examples of the Qt Toolkit.
00007 **
00008 ** $QT_BEGIN_LICENSE:BSD$
00009 ** Commercial License Usage
00010 ** Licensees holding valid commercial Qt licenses may use this file in
00011 ** accordance with the commercial license agreement provided with the
00012 ** Software or, alternatively, in accordance with the terms contained in
00013 ** a written agreement between you and The Qt Company. For licensing terms
00014 ** and conditions see https://www.qt.io/terms-conditions. For further
00015 ** information use the contact form at https://www.qt.io/contact-us.
00016 **
00017 ** BSD License Usage
00018 ** Alternatively, you may use this file under the terms of the BSD license
00019 ** as follows:
00020 **
00021 ** "Redistribution and use in source and binary forms, with or without
00022 ** modification, are permitted provided that the following conditions are
00023 ** met:
00024 **   * Redistributions of source code must retain the above copyright
00025 **     notice, this list of conditions and the following disclaimer.
00026 **   * Redistributions in binary form must reproduce the above copyright
00027 **     notice, this list of conditions and the following disclaimer in
00028 **     the documentation and/or other materials provided with the
00029 **     distribution.
00030 **   * Neither the name of The Qt Company Ltd nor the names of its
00031 **     contributors may be used to endorse or promote products derived
00032 **     from this software without specific prior written permission.
00033 **
00034 **
00035 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00036 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00037 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00038 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00039 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00042 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00043 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00044 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00045 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00046 **
00047 ** $QT_END_LICENSE$
00048 **
00049 ****************************************************************************/
00050 
00051 #include "video_cheatsheet.h"
00052 
00053 #include <QtWidgets>
00054 #include <QVideoWidget>
00055 #include <QDebug>
00056 #include <QSize>
00057 
00058 HelpVideo::HelpVideo(QWidget *parent)
00059     : QDialog(parent)
00060 {
00061     setWindowTitle("Cheatsheet");
00062     _media_player = new QMediaPlayer(this, QMediaPlayer::VideoSurface);
00063     QVideoWidget *videoWidget = new QVideoWidget;
00064 
00065     videoWidget->setAutoFillBackground(true);
00066     auto palette = videoWidget->palette();
00067     palette.setColor( QPalette::Window, Qt::white);
00068     videoWidget->setPalette(palette);
00069     videoWidget->setAttribute(Qt::WA_OpaquePaintEvent, true);
00070 
00071     _playlist = new QMediaPlaylist();
00072     QListWidget* list_widget = new QListWidget();
00073     _text = new QLabel("placeholder");
00074 
00075     _media_player->setPlaylist(_playlist);
00076 
00077     _playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
00078 
00079     list_widget->setSelectionMode(QAbstractItemView::SingleSelection);
00080 
00081     _text->setFixedWidth(600);
00082 
00083     videoWidget->setFixedSize( QSize(900,600) );
00084     list_widget->setMinimumWidth(200);
00085 
00086     QBoxLayout *videoLayout = new QVBoxLayout;
00087 
00088     videoLayout->setMargin(20);
00089     videoLayout->setSpacing(20);
00090     videoLayout->addWidget(_text);
00091     videoLayout->addWidget(videoWidget);
00092     videoLayout->addWidget(new QLabel("If you can't see the videos, install codecs with [sudo apt-get install libqt5multimedia5-plugins]"));
00093 
00094     videoLayout->setStretch(0,1);
00095     videoLayout->setStretch(1,0);
00096     videoLayout->setStretch(2,0);
00097 
00098     QBoxLayout *layout = new QHBoxLayout;
00099     layout->addWidget(list_widget);
00100     layout->addLayout(videoLayout);
00101 
00102     setLayout(layout);
00103 
00104     _media_player->setVideoOutput(videoWidget);
00105 
00106     connect(_media_player,
00107             static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
00108             this, &HelpVideo::handleError);
00109 
00110     setupHelps();
00111 
00112     for(const auto& section: _help_sections)
00113     {
00114         list_widget->addItem( section.title );
00115         _playlist->addMedia( section.video_url );
00116     }
00117 
00118     _text->setWordWrap(true);
00119 
00120     connect( list_widget, &QListWidget::currentRowChanged, this, [this](int row)
00121     {
00122          _playlist->setCurrentIndex(row);
00123          QString label_text = QString("<h2>%1</h2>%2").arg(_help_sections[row].title, _help_sections[row].text);
00124          _text->setText( label_text );
00125          _media_player->play();
00126     });
00127 
00128     list_widget->item(0)->setSelected(true);
00129 }
00130 
00131 HelpVideo::~HelpVideo()
00132 {
00133 }
00134 
00135 
00136 void HelpVideo::setupHelps()
00137 {
00138     _help_sections.push_back( {"Add timeseries to plot",
00139                                "Drag and Drop timeseries from the the list on the left side"
00140                                " using the <b>Left Mouse</b> button.",
00141                               QUrl("qrc:/cheatsheet/video/cheatsheet-drag-drop.mp4")});
00142 
00143     _help_sections.push_back( {"Create XY plots",
00144                                "Using two timeseries, sharing the same time axis, it is possible"
00145                                " to create a XY plot. Drag and Drop the Y axis as usual, using the"
00146                                " <b>Left Mouse</b> and the X axis with the <b>Right Mouse</b>.",
00147                               QUrl("qrc:/cheatsheet/video/cheatsheet-xy.mp4")});
00148 
00149     _help_sections.push_back( {"Pan view",
00150                                "To pan the plot area, either use the <b>Middle Mouse</b> button or"
00151                                " <b>CTRL + Left Mouse</b>.",
00152                               QUrl("qrc:/cheatsheet/video/cheatsheet-pan-view.mp4")});
00153 
00154     _help_sections.push_back( {"Remove Columns/Rows",
00155                                "To remove entire columns or/and rows, you must first clear all the curves.",
00156                               QUrl("qrc:/cheatsheet/video/cheatsheet-remove-column.mp4")});
00157 
00158     _help_sections.push_back( {"Resize Fonts",
00159                                "To change the size of the fonts used in the legend or the list of timeseries"
00160                                " on the left side, use <b>CTRL + Mouse Wheel</b>",
00161                               QUrl("qrc:/cheatsheet/video/cheatsheet-resize-font.mp4")});
00162 
00163     _help_sections.push_back( {"Swap Plots",
00164                               "Swap two plots using <b>CTRL + Right Mouse</b>.",
00165                               QUrl("qrc:/cheatsheet/video/cheatsheet-swap.mp4")});
00166 
00167     _help_sections.push_back( {"Time tracker",
00168                               "The time tracker is a vertical line that is helpful to visualize the"
00169                                " value of the timeseries at a given time.<br>"
00170                                "Furthermore, it is connected to the Publishers plugins: every time the time"
00171                                " tracker is activated, all the active publisher are called."
00172                                " Move the tracker either using the <b>Slider</b> at the bottom or pressing"
00173                                "<b> SHIFT + Left Mouse</b>.",
00174                               QUrl("qrc:/cheatsheet/video/cheatsheet-tracker.mp4")});
00175 
00176 
00177     _help_sections.push_back( {"Zoom Area",
00178                               "Click with the <b>Left Mouse</b> button on the plot area"
00179                               " and select the rectangle to zoom in.",
00180                               QUrl("qrc:/cheatsheet/video/cheatsheet-zoom-area.mp4")});
00181 
00182     _help_sections.push_back( {"Zoom In and Out",
00183                                "Use the <b>Mouse Wheel</b> to zoom in or out.<br>"
00184                                "Additionally, you can zoom a single axis moving the mouse cursor"
00185                                " either on the bottom X scale (<b>zoom horizontally only</b>) or on the left"
00186                                " Y scale (<b>zoom vertically only</b>).",
00187                               QUrl("qrc:/cheatsheet/video/cheatsheet-zoom-in-out.mp4")});
00188 }
00189 
00190 
00191 
00192 void HelpVideo::handleError(QMediaPlayer::Error)
00193 {
00194 
00195     const QString errorString = _media_player->errorString();
00196     QString message = "Error: ";
00197     if (errorString.isEmpty())
00198         message += " #" + QString::number(int(_media_player->error()));
00199     else
00200         message += errorString;
00201     qDebug() << message;
00202 }


plotjuggler
Author(s): Davide Faconti
autogenerated on Wed Jul 3 2019 19:28:05