2
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
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.
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.
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/>.
20
#include <QAbstractButton>
24
KPToolBar::KPToolBar(const QString& title, QWidget* parent)
25
: QToolBar(title, parent)
30
KPToolBar::KPToolBar(QWidget* parent)
38
m_expandButton = findChild<QAbstractButton*>("qt_toolbar_ext_button");
39
m_expandTimer.setSingleShot(true);
40
connect(&m_expandTimer, &QTimer::timeout, this, [this] { setExpanded(false); });
43
bool KPToolBar::isExpanded()
45
return !canExpand() || (canExpand() && m_expandButton->isChecked());
48
bool KPToolBar::canExpand()
50
return m_expandButton && m_expandButton->isVisible();
53
void KPToolBar::setExpanded(bool state)
55
if (canExpand() && !QMetaObject::invokeMethod(layout(), "setExpanded", Q_ARG(bool, state))) {
56
qWarning("Toolbar: Cannot invoke setExpanded!");
60
bool KPToolBar::event(QEvent* event)
62
// Override events handled by the base class for better UX when using an expandable toolbar.
63
switch (event->type()) {
65
// Hide the toolbar after 2 seconds of mouse exit
66
m_expandTimer.start(2000);
69
// Mouse came back in, stop hiding timer
73
return QToolBar::event(event);