diff --git a/src/PushButton.cpp b/src/PushButton.cpp new file mode 100644 index 0000000..ad120cf --- /dev/null +++ b/src/PushButton.cpp @@ -0,0 +1,69 @@ +//============================================================================ +/// \file PushButton.cpp +/// \author Uwe Kindler +/// \date 18.10.2022 +/// \brief Implementation of CPushButton +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "PushButton.h" + +#include +#include +#include +#include + + +namespace ads +{ +QSize CPushButton::sizeHint() const +{ + QSize sh = QPushButton::sizeHint(); + + if (m_Orientation != CPushButton::Horizontal) + { + sh.transpose(); + } + + return sh; +} + +void CPushButton::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QStylePainter painter(this); + QStyleOptionButton option; + initStyleOption(&option); + + if (m_Orientation == CPushButton::VerticalTopToBottom) + { + painter.rotate(90); + painter.translate(0, -1 * width()); + option.rect = option.rect.transposed(); + } + else if (m_Orientation == CPushButton::VerticalBottomToTop) + { + painter.rotate(-90); + painter.translate(-1 * height(), 0); + option.rect = option.rect.transposed(); + } + + painter.drawControl(QStyle::CE_PushButton, option); +} + +CPushButton::Orientation CPushButton::orientation() const +{ + return m_Orientation; +} + +void CPushButton::setOrientation(Orientation &orientation) +{ + m_Orientation = orientation; +} +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF PushButton.cpp diff --git a/src/PushButton.h b/src/PushButton.h new file mode 100644 index 0000000..9eac3bc --- /dev/null +++ b/src/PushButton.h @@ -0,0 +1,49 @@ +#ifndef PushButtonH +#define PushButtonH +//============================================================================ +/// \file PushButton.h +/// \author Uwe Kindler +/// \date 18.10.2022 +/// \brief Declaration of CPushButton +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +namespace ads +{ + +/** + * ADS specific push button class + */ +class CPushButton : public QPushButton +{ + Q_OBJECT +public: + enum Orientation { + Horizontal, + VerticalTopToBottom, + VerticalBottomToTop + }; + + using QPushButton::QPushButton; + + virtual QSize sizeHint() const override; + + Orientation orientation() const; + void setOrientation(Orientation &orientation); + +protected: + virtual void paintEvent(QPaintEvent *event) override; + +private: + Orientation m_Orientation = Horizontal; +}; + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // PushButtonH + diff --git a/src/src.pro b/src/src.pro index e86ebad..d0422db 100644 --- a/src/src.pro +++ b/src/src.pro @@ -50,7 +50,8 @@ HEADERS += \ DockFocusController.h \ AutoHideDockContainer.h \ SideTabBar.h \ - DockWidgetSideTab.h + DockWidgetSideTab.h \ + PushButton.h SOURCES += \ @@ -73,7 +74,8 @@ SOURCES += \ DockFocusController.cpp \ AutoHideDockContainer.cpp \ SideTabBar.cpp \ - DockWidgetSideTab.cpp + DockWidgetSideTab.cpp \ + PushButton.cpp unix:!macx {