#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 set( MOC_HEADER_FILES
cafFrameAnimationControl.h cafFrameAnimationControl.h
cafAnimationToolBar.h cafAnimationToolBar.h
cafPopupWidget.h cafPopupMenuButton.h
) )
if (CAF_USE_QT5) if (CAF_USE_QT5)
@ -43,8 +43,8 @@ set( PROJECT_FILES
cafFrameAnimationControl.cpp cafFrameAnimationControl.cpp
cafAnimationToolBar.h cafAnimationToolBar.h
cafAnimationToolBar.cpp cafAnimationToolBar.cpp
cafPopupWidget.h cafPopupMenuButton.h
cafPopupWidget.cpp cafPopupMenuButton.cpp
) )
add_library( ${PROJECT_NAME} add_library( ${PROJECT_NAME}

View File

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

View File

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

View File

@ -33,52 +33,44 @@
// for more details. // for more details.
// //
//################################################################################################## //##################################################################################################
#include "cafPopupWidget.h" #include "cafPopupMenuButton.h"
#include <QDebug> #include <QHBoxLayout>
#include <QHideEvent> #include <QMenu>
#include <QToolButton> #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)));
}
//-------------------------------------------------------------------------------------------------- PopupMenuButton::PopupMenuButton(QWidget* parentWidget,
/// Qt::Orientation orientation /*= Qt::Horizontal*/,
//-------------------------------------------------------------------------------------------------- ToolButtonPopupMode popupMode /*=InstantPopup*/)
void caf::PopupWidget::buttonClicked(bool checked) : QToolButton(parentWidget)
{ {
QToolButton* parentButton = static_cast<QToolButton*>(this->parentWidget()); if (orientation == Qt::Horizontal)
if (checked)
{ {
QRect buttonRect = parentButton->contentsRect(); m_layout = new QHBoxLayout(this);
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 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*) void caf::PopupMenuButton::addWidget(QWidget* widget, int stretch, Qt::Alignment alignment)
{
}
//--------------------------------------------------------------------------------------------------
/// Hides window but also unchecks the owning tool bar button
//--------------------------------------------------------------------------------------------------
void caf::PopupWidget::hideEvent(QHideEvent* event)
{ {
m_layout->addWidget(widget, stretch, alignment);
} }

View File

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