• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mixxxdj / mixxx / 11616838164

31 Oct 2024 05:26PM CUT coverage: 31.815% (-0.1%) from 31.928%
11616838164

Pull #13818

github

web-flow
Merge 5ad242bcf into edae0ca3b
Pull Request #13818: Track Info Dialog: Improve keyboard usability & resize behavior

0 of 462 new or added lines in 14 files covered. (0.0%)

10 existing lines in 3 files now uncovered.

33278 of 104597 relevant lines covered (31.82%)

48267.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/widget/wbasicpushbutton.cpp
1
#include "widget/wbasicpushbutton.h"
2

3
#include <QPaintEvent>
4
#include <QStyleOption>
5
#include <QStylePainter>
6
#include <QToolTip>
7

8
#include "moc_wbasicpushbutton.cpp"
9

10
namespace {
NEW
11
void elideButtonLabelIfNeeded(QStyleOptionButton& option,
×
12
        QStyle* style,
13
        QWidget* widget,
14
        Qt::TextElideMode elideMode) {
NEW
15
    if (elideMode == Qt::ElideNone) {
×
NEW
16
        return;
×
17
    }
18

19
    // Calculate how much space we have left for the text
NEW
20
    QSize textSize = style->subElementRect(QStyle::SE_PushButtonContents, &option, widget).size();
×
21

NEW
22
    if (option.features & QStyleOptionButton::HasMenu) {
×
NEW
23
        int indicatorSize = style->pixelMetric(QStyle::PM_MenuButtonIndicator, &option, widget);
×
NEW
24
        textSize.setWidth(textSize.width() - indicatorSize);
×
25
    }
26

NEW
27
    if (!option.icon.isNull()) {
×
NEW
28
        int iconSpacing = 4; // ### 4 is currently hardcoded in QPushButton::sizeHint()
×
NEW
29
        textSize.setWidth(textSize.width() - option.iconSize.width() - iconSpacing);
×
30
    }
31

32
    // Replace overflowing text with ellipsis ("...")
NEW
33
    option.text = option.fontMetrics.elidedText(option.text, elideMode, textSize.width());
×
34
}
35
} // namespace
36

NEW
37
WBasicPushButton::WBasicPushButton(QWidget* pParent)
×
38
        : QPushButton(pParent),
NEW
39
          m_elideMode(Qt::ElideNone) {
×
NEW
40
}
×
41

NEW
42
void WBasicPushButton::setElideMode(Qt::TextElideMode elideMode) {
×
NEW
43
    if (elideMode != m_elideMode) {
×
NEW
44
        m_elideMode = elideMode;
×
NEW
45
        updateGeometry();
×
46
    }
NEW
47
}
×
48

NEW
49
QSize WBasicPushButton::minimumSizeHint() const {
×
NEW
50
    QSize fullSize = sizeHint();
×
51

NEW
52
    if (m_elideMode == Qt::ElideNone) {
×
53
        // Elision of overflowing text is disabled,
54
        // so this button cannot be collapsed beyond
55
        // its default size.
NEW
56
        return fullSize;
×
57
    } else {
58
        // Elision of overflowing text is enabled.
NEW
59
        return QSize(0, fullSize.height());
×
60
    }
61
}
62

NEW
63
void WBasicPushButton::paintEvent(QPaintEvent* /*unused*/) {
×
NEW
64
    QStylePainter p(this);
×
NEW
65
    QStyleOptionButton option;
×
NEW
66
    initStyleOption(&option);
×
NEW
67
    elideButtonLabelIfNeeded(option, p.style(), this, m_elideMode);
×
NEW
68
    p.drawControl(QStyle::CE_PushButton, option);
×
NEW
69
}
×
70

NEW
71
QString WBasicPushButton::buildToolTip() const {
×
72
    // Show the button label as a tooltip when the label text
73
    // is partially hidden due to the button's size
74

NEW
75
    QString txtToolTip = toolTip();
×
76

NEW
77
    if (!txtToolTip.isEmpty()) {
×
NEW
78
        return txtToolTip;
×
79
    }
80

NEW
81
    QString txtLabel = text();
×
NEW
82
    QSize currentSize = size();
×
NEW
83
    QSize fullSize = sizeHint();
×
84

NEW
85
    if ((currentSize.height() < fullSize.height() ||
×
NEW
86
                currentSize.width() < fullSize.width()) &&
×
NEW
87
            !txtLabel.isEmpty()) {
×
88
        // The label text is not fully visible,
89
        // so show it as a tooltip
NEW
90
        return txtLabel;
×
91
    }
92

NEW
93
    return QString();
×
NEW
94
}
×
95

NEW
96
bool WBasicPushButton::event(QEvent* e) {
×
NEW
97
    switch (e->type()) {
×
NEW
98
    case QEvent::ToolTip: {
×
NEW
99
        QString toolTipToShow = buildToolTip();
×
NEW
100
        if (!toolTipToShow.isEmpty()) {
×
NEW
101
            QToolTip::showText(static_cast<QHelpEvent*>(e)->globalPos(),
×
102
                    toolTipToShow,
103
                    this,
NEW
104
                    QRect(),
×
105
                    toolTipDuration());
106
        } else {
NEW
107
            e->ignore();
×
108
        }
NEW
109
        return true;
×
NEW
110
    }
×
NEW
111
    default: {
×
NEW
112
        return QPushButton::event(e);
×
113
    }
114
    }
115
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc