First implementation of cafPopupWidget and used for animation speed

This commit is contained in:
Gaute Lindkvist 2019-02-12 12:21:13 +01:00
parent 2b9f6e10bc
commit 7e43509f41
5 changed files with 181 additions and 12 deletions

View File

@ -14,6 +14,7 @@ endif(CAF_USE_QT5)
set( MOC_HEADER_FILES
cafFrameAnimationControl.h
cafAnimationToolBar.h
cafPopupWidget.h
)
if (CAF_USE_QT5)
@ -42,6 +43,8 @@ set( PROJECT_FILES
cafFrameAnimationControl.cpp
cafAnimationToolBar.h
cafAnimationToolBar.cpp
cafPopupWidget.h
cafPopupWidget.cpp
)
add_library( ${PROJECT_NAME}

View File

@ -42,6 +42,7 @@
#include <QLabel>
#include <QLineEdit>
#include <QToolButton>
#include <QHBoxLayout>
namespace caf
{
@ -91,22 +92,37 @@ void AnimationToolBar::init()
m_animRepeatFromStartAction = new QAction(QIcon(":/cafAnimControl/RepeatFromStart.png"), tr("Repeat From start"), this);
m_animRepeatFromStartAction->setCheckable(true);
m_animSpeedButton = new QToolButton(this);
m_animSpeedButton->setIcon(QIcon(":/cafAnimControl/Fast.png"));
m_animSpeedButton->setToolTip("Adjust Animation Speed");
m_animSpeedButton->setCheckable(true);
m_timestepCombo = new QComboBox(this);
m_timestepCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_timestepCombo->setToolTip(tr("Current Time Step"));
QLabel* slowLabel = new QLabel ( this);
slowLabel->setPixmap(QPixmap(":/cafAnimControl/Slow.png"));
slowLabel->setToolTip(tr("Slow"));
QLabel* fastLabel = new QLabel(this);
fastLabel->setPixmap(QPixmap(":/cafAnimControl/Fast.png"));
fastLabel->setAlignment(Qt::AlignRight);
fastLabel->setToolTip(tr("Fast"));
m_frameRateSlowLabel = new QLabel(this);
m_frameRateSlowLabel->setPixmap(QPixmap(":/cafAnimControl/Slow.png"));
m_frameRateSlowLabel->setToolTip(tr("Slow"));
m_frameRateFastLabel = new QLabel(this);
m_frameRateFastLabel->setPixmap(QPixmap(":/cafAnimControl/Fast.png"));
m_frameRateFastLabel->setToolTip(tr("Fast"));
m_frameRateFastLabel->setAlignment(Qt::AlignRight);
m_frameRateSlider = new QSlider(Qt::Horizontal, this);
m_frameRateSlider->setMaximumWidth(75);
m_frameRateSlider->setToolTip(tr("Animation speed"));
m_frameRatePopup = new PopupWidget(m_animSpeedButton);
QHBoxLayout* frameRatePopupLayout = new QHBoxLayout(m_frameRatePopup);
frameRatePopupLayout->setContentsMargins(QMargins(2, 2, 2, 2));
m_frameRatePopup->setLayout(frameRatePopupLayout);
frameRatePopupLayout->addWidget(m_frameRateSlowLabel);
frameRatePopupLayout->addWidget(m_frameRateSlider);
frameRatePopupLayout->addWidget(m_frameRateFastLabel);
QAction* separator1 = new QAction(this);
separator1->setSeparator(true);
QAction* separator2 = new QAction(this);
@ -126,10 +142,8 @@ void AnimationToolBar::init()
addAction(m_animRepeatFromStartAction );
addAction(separator2);
addWidget(slowLabel);
addWidget(m_frameRateSlider);
addWidget(fastLabel);
addWidget(m_animSpeedButton);
addAction(separator3);

View File

@ -39,8 +39,10 @@
#include <QToolBar>
#include <QPointer>
#include <QToolButton>
#include "cafFrameAnimationControl.h"
#include "cafPopupWidget.h"
class QComboBox;
class QLabel;
@ -91,10 +93,14 @@ private:
QAction* m_animPlayAction;
QAction* m_animStepForwardAction;
QAction* m_animSkipToEndAction;
QToolButton* m_animSpeedButton;
QAction* m_animRepeatFromStartAction;
QLabel* m_frameRateFastLabel;
QLabel* m_frameRateSlowLabel;
QSlider* m_frameRateSlider;
PopupWidget* m_frameRatePopup;
QComboBox* m_timestepCombo;

View File

@ -0,0 +1,84 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2019- Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafPopupWidget.h"
#include <QDebug>
#include <QHideEvent>
#include <QToolButton>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PopupWidget::PopupWidget(QToolButton* parentButton)
: QWidget(parentButton, Qt::Popup | Qt::FramelessWindowHint)
{
QObject::connect(parentButton, SIGNAL(clicked(bool)), this, SLOT(buttonClicked(bool)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PopupWidget::buttonClicked(bool checked)
{
QToolButton* parentButton = static_cast<QToolButton*>(this->parentWidget());
if (checked)
{
QRect buttonRect = parentButton->contentsRect();
QPoint buttonLeftPos = parentButton->mapToGlobal(buttonRect.bottomLeft());
QSize currentSize = this->size();
setGeometry(buttonLeftPos.x() - currentSize.width() / 2, buttonLeftPos.y() + 2, currentSize.width(), currentSize.height());
show();
}
else
{
hide();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PopupWidget::showEvent(QShowEvent*)
{
}
//--------------------------------------------------------------------------------------------------
/// Hides window but also unchecks the owning tool bar button
//--------------------------------------------------------------------------------------------------
void caf::PopupWidget::hideEvent(QHideEvent* event)
{
}

View File

@ -0,0 +1,62 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2019- Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QWidget>
class QToolButton;
namespace caf
{
//==================================================================================================
///
//==================================================================================================
class PopupWidget : public QWidget
{
Q_OBJECT
public:
PopupWidget(QToolButton* parentButton);
public slots:
void buttonClicked(bool checked);
protected:
void showEvent(QShowEvent*) override;
void hideEvent(QHideEvent*) override;
private:
};
}