File: PushButton.cpp

package info (click to toggle)
qt-advanced-docking-system 4.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,492 kB
  • sloc: cpp: 16,302; python: 1,392; makefile: 12
file content (70 lines) | stat: -rw-r--r-- 1,754 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//============================================================================
/// \file   PushButton.cpp
/// \author Uwe Kindler
/// \date   18.10.2022
/// \brief  Implementation of CPushButton
//============================================================================

//============================================================================
//                                   INCLUDES
//============================================================================
#include "PushButton.h"

#include <QPainter>
#include <QStyleOptionButton>
#include <QDebug>
#include <QStylePainter>


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::buttonOrientation() const
{
    return m_Orientation;
}

void CPushButton::setButtonOrientation(Orientation orientation)
{
    m_Orientation = orientation;
    updateGeometry();
}
} // namespace ads

//---------------------------------------------------------------------------
// EOF PushButton.cpp