File indexing completed on 2024-05-12 15:28:21
0001 /*************************************************************************** 0002 File : SlidingPanel.cpp 0003 Project : LabPlot 0004 Description : Sliding panel shown in the presenter widget 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2016 by Fabian Kristof (fkristofszabolcs@gmail.com) 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 * This program is distributed in the hope that it will be useful, * 0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0019 * GNU General Public License for more details. * 0020 * * 0021 * You should have received a copy of the GNU General Public License * 0022 * along with this program; if not, write to the Free Software * 0023 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0024 * Boston, MA 02110-1301 USA * 0025 * * 0026 ***************************************************************************/ 0027 #include "SlidingPanel.h" 0028 0029 #include <QApplication> 0030 #include <QHBoxLayout> 0031 #include <QLabel> 0032 #include <QPushButton> 0033 #include <QScreen> 0034 #include <QSize> 0035 0036 #include <KLocalizedString> 0037 0038 SlidingPanel::SlidingPanel(QWidget *parent, const QString &worksheetName) : QFrame(parent) { 0039 setAttribute(Qt::WA_DeleteOnClose); 0040 0041 m_worksheetName = new QLabel(worksheetName); 0042 QFont nameFont; 0043 nameFont.setPointSize(20); 0044 nameFont.setBold(true); 0045 m_worksheetName->setFont(nameFont); 0046 0047 m_quitPresentingMode = new QPushButton(i18n("Quit Presentation")); 0048 m_quitPresentingMode->setIcon(QIcon::fromTheme(QLatin1String("window-close"))); 0049 0050 auto* hlayout = new QHBoxLayout; 0051 hlayout->addWidget(m_worksheetName); 0052 auto* spacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum); 0053 hlayout->addItem(spacer); 0054 hlayout->addWidget(m_quitPresentingMode); 0055 setLayout(hlayout); 0056 0057 QPalette pal(palette()); 0058 pal.setColor(QPalette::Window, Qt::gray); 0059 setAutoFillBackground(true); 0060 setPalette(pal); 0061 0062 move(0, 0); 0063 raise(); 0064 show(); 0065 } 0066 0067 SlidingPanel::~SlidingPanel() { 0068 delete m_worksheetName; 0069 delete m_quitPresentingMode; 0070 } 0071 0072 void SlidingPanel::movePanel(qreal value) { 0073 move(0, -height() + static_cast<int>(value * height()) ); 0074 raise(); 0075 } 0076 0077 QPushButton* SlidingPanel::quitButton() const { 0078 return m_quitPresentingMode; 0079 } 0080 0081 QSize SlidingPanel::sizeHint() const { 0082 QSize sh; 0083 const QRect& screenSize = QGuiApplication::primaryScreen()->availableGeometry(); 0084 sh.setWidth(screenSize.width()); 0085 sh.setHeight(m_worksheetName->sizeHint().height() 0086 + layout()->contentsMargins().top() + layout()->contentsMargins().bottom()); 0087 0088 return sh; 0089 }