#4054 More toolbar adjustments

This commit is contained in:
Gaute Lindkvist 2019-02-12 14:36:14 +01:00
parent 7e43509f41
commit 33eea61852
5 changed files with 50 additions and 64 deletions

View File

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

View File

@ -37,12 +37,13 @@
#include "cafAnimationToolBar.h"
#include "cafPopupMenuButton.h"
#include <QAction>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QToolButton>
#include <QHBoxLayout>
namespace caf
{
@ -92,14 +93,9 @@ 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 = new PopupMenuButton(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"));
m_frameRateSlowLabel = new QLabel(this);
m_frameRateSlowLabel->setPixmap(QPixmap(":/cafAnimControl/Slow.png"));
@ -112,16 +108,15 @@ void AnimationToolBar::init()
m_frameRateSlider = new QSlider(Qt::Horizontal, this);
m_frameRateSlider->setToolTip(tr("Animation speed"));
m_frameRatePopup = new PopupWidget(m_animSpeedButton);
m_frameRateSlider->setMinimumWidth(100);
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);
m_animSpeedButton->addWidget(m_frameRateSlowLabel);
m_animSpeedButton->addWidget(m_frameRateSlider);
m_animSpeedButton->addWidget(m_frameRateFastLabel);
m_timestepCombo = new QComboBox(this);
m_timestepCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_timestepCombo->setToolTip(tr("Current Time Step"));
QAction* separator1 = new QAction(this);
separator1->setSeparator(true);

View File

@ -37,12 +37,10 @@
#pragma once
#include <QToolBar>
#include <QPointer>
#include <QToolButton>
#include <QToolBar>
#include "cafFrameAnimationControl.h"
#include "cafPopupWidget.h"
class QComboBox;
class QLabel;
@ -52,6 +50,7 @@ class QToolButton;
namespace caf
{
class PopupMenuButton;
//==================================================================================================
///
@ -93,14 +92,13 @@ private:
QAction* m_animPlayAction;
QAction* m_animStepForwardAction;
QAction* m_animSkipToEndAction;
QToolButton* m_animSpeedButton;
QAction* m_animRepeatFromStartAction;
PopupMenuButton* m_animSpeedButton;
QLabel* m_frameRateFastLabel;
QLabel* m_frameRateSlowLabel;
QSlider* m_frameRateSlider;
PopupWidget* m_frameRatePopup;
QComboBox* m_timestepCombo;

View File

@ -33,52 +33,44 @@
// for more details.
//
//##################################################################################################
#include "cafPopupWidget.h"
#include "cafPopupMenuButton.h"
#include <QDebug>
#include <QHideEvent>
#include <QToolButton>
#include <QHBoxLayout>
#include <QMenu>
#include <QVBoxLayout>
using namespace caf;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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)
PopupMenuButton::PopupMenuButton(QWidget* parentWidget,
Qt::Orientation orientation /*= Qt::Horizontal*/,
ToolButtonPopupMode popupMode /*=InstantPopup*/)
: QToolButton(parentWidget)
{
QToolButton* parentButton = static_cast<QToolButton*>(this->parentWidget());
if (checked)
if (orientation == Qt::Horizontal)
{
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();
m_layout = new QHBoxLayout(this);
}
else
{
hide();
m_layout = new QVBoxLayout(this);
}
m_layout->setContentsMargins(QMargins(2, 2, 2, 2));
QMenu* menu = new QMenu(this);
menu->setLayout(m_layout);
setMenu(menu);
setCheckable(true);
setPopupMode(popupMode);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PopupWidget::showEvent(QShowEvent*)
{
}
//--------------------------------------------------------------------------------------------------
/// Hides window but also unchecks the owning tool bar button
//--------------------------------------------------------------------------------------------------
void caf::PopupWidget::hideEvent(QHideEvent* event)
void caf::PopupMenuButton::addWidget(QWidget* widget, int stretch, Qt::Alignment alignment)
{
m_layout->addWidget(widget, stretch, alignment);
}

View File

@ -34,9 +34,10 @@
//
//##################################################################################################
#pragma once
#include <QPointer>
#include <QToolButton>
#include <QWidget>
class QBoxLayout;
class QToolButton;
namespace caf
@ -44,19 +45,19 @@ namespace caf
//==================================================================================================
///
//==================================================================================================
class PopupWidget : public QWidget
class PopupMenuButton : public QToolButton
{
Q_OBJECT
public:
PopupWidget(QToolButton* parentButton);
PopupMenuButton(QWidget* parentWidget,
Qt::Orientation orientation = Qt::Horizontal,
ToolButtonPopupMode popupMode = InstantPopup);
public slots:
void buttonClicked(bool checked);
protected:
void showEvent(QShowEvent*) override;
void hideEvent(QHideEvent*) override;
void addWidget(QWidget* widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment());
private:
private:
QPointer<QBoxLayout> m_layout;
};
}