keepassxc

Форк
0
/
KPToolBar.cpp 
75 строк · 2.1 Кб
1
/*
2
 *  Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "KPToolBar.h"
19

20
#include <QAbstractButton>
21
#include <QEvent>
22
#include <QLayout>
23

24
KPToolBar::KPToolBar(const QString& title, QWidget* parent)
25
    : QToolBar(title, parent)
26
{
27
    init();
28
}
29

30
KPToolBar::KPToolBar(QWidget* parent)
31
    : QToolBar(parent)
32
{
33
    init();
34
}
35

36
void KPToolBar::init()
37
{
38
    m_expandButton = findChild<QAbstractButton*>("qt_toolbar_ext_button");
39
    m_expandTimer.setSingleShot(true);
40
    connect(&m_expandTimer, &QTimer::timeout, this, [this] { setExpanded(false); });
41
}
42

43
bool KPToolBar::isExpanded()
44
{
45
    return !canExpand() || (canExpand() && m_expandButton->isChecked());
46
}
47

48
bool KPToolBar::canExpand()
49
{
50
    return m_expandButton && m_expandButton->isVisible();
51
}
52

53
void KPToolBar::setExpanded(bool state)
54
{
55
    if (canExpand() && !QMetaObject::invokeMethod(layout(), "setExpanded", Q_ARG(bool, state))) {
56
        qWarning("Toolbar: Cannot invoke setExpanded!");
57
    }
58
}
59

60
bool KPToolBar::event(QEvent* event)
61
{
62
    // Override events handled by the base class for better UX when using an expandable toolbar.
63
    switch (event->type()) {
64
    case QEvent::Leave:
65
        // Hide the toolbar after 2 seconds of mouse exit
66
        m_expandTimer.start(2000);
67
        return true;
68
    case QEvent::Enter:
69
        // Mouse came back in, stop hiding timer
70
        m_expandTimer.stop();
71
        return true;
72
    default:
73
        return QToolBar::event(event);
74
    }
75
}
76

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.