File indexing completed on 2024-05-12 15:28:21
0001 /*************************************************************************** 0002 File : PresenterWidget.cpp 0003 Project : LabPlot 0004 Description : Widget for static presenting of worksheets 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2016 by Fabian Kristof (fkristofszabolcs@gmail.com) 0007 Copyright : (C) 2018-2020 Alexander Semke (alexander.semke@web.de) 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 #include "PresenterWidget.h" 0029 #include "SlidingPanel.h" 0030 0031 #include <QApplication> 0032 #include <QKeyEvent> 0033 #include <QLabel> 0034 #include <QPushButton> 0035 #include <QScreen> 0036 #include <QTimeLine> 0037 0038 PresenterWidget::PresenterWidget(const QPixmap &pixmap, const QString& worksheetName, QWidget *parent) : QWidget(parent), 0039 m_imageLabel(new QLabel(this)), m_timeLine(new QTimeLine(600)) { 0040 0041 setAttribute(Qt::WA_DeleteOnClose); 0042 m_imageLabel->setPixmap(pixmap); 0043 m_imageLabel->adjustSize(); 0044 0045 const QRect& screenSize = QGuiApplication::primaryScreen()->availableGeometry(); 0046 0047 const int moveRight = (screenSize.width() - m_imageLabel->width()) / 2.0; 0048 const int moveDown = (screenSize.height() - m_imageLabel->height()) / 2.0; 0049 m_imageLabel->move(moveRight, moveDown); 0050 0051 m_panel = new SlidingPanel(this, worksheetName); 0052 qApp->installEventFilter(this); 0053 connect(m_timeLine, &QTimeLine::valueChanged, m_panel, &SlidingPanel::movePanel); 0054 connect(m_panel->quitButton(), &QPushButton::clicked, this, [=]() {close();}); 0055 } 0056 0057 PresenterWidget::~PresenterWidget() { 0058 delete m_imageLabel; 0059 delete m_timeLine; 0060 } 0061 0062 bool PresenterWidget::eventFilter(QObject* watched, QEvent* event) { 0063 Q_UNUSED(watched); 0064 if (event->type() == QEvent::MouseMove) { 0065 if (m_panel->y() != 0 && m_panel->rect().contains(QCursor::pos())) 0066 slideDown(); 0067 else if (m_panel->y() == 0 && !m_panel->rect().contains(QCursor::pos())) 0068 slideUp(); 0069 } 0070 0071 return false; 0072 } 0073 0074 void PresenterWidget::keyPressEvent(QKeyEvent *event) { 0075 if (event->key() == Qt::Key_Escape) 0076 close(); 0077 } 0078 0079 void PresenterWidget::focusOutEvent(QFocusEvent*) { 0080 close(); 0081 } 0082 0083 void PresenterWidget::slideDown() { 0084 m_timeLine->setDirection(QTimeLine::Forward); 0085 startTimeline(); 0086 } 0087 0088 void PresenterWidget::slideUp() { 0089 m_timeLine->setDirection(QTimeLine::Backward); 0090 startTimeline(); 0091 } 0092 0093 void PresenterWidget::startTimeline() { 0094 if (m_timeLine->state() != QTimeLine::Running) 0095 m_timeLine->start(); 0096 }