1 /*
2     This file is part of the Kasten Framework, made within the KDE community.
3 
4     SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8 
9 #include "abstracttoolwidget_p.hpp"
10 
11 // Qt
12 #include <QPushButton>
13 #include <QShortcut>
14 
15 namespace Kasten {
16 
AbstractToolWidgetPrivate(AbstractToolWidget * parent)17 AbstractToolWidgetPrivate::AbstractToolWidgetPrivate(AbstractToolWidget* parent)
18     : p(parent)
19 
20 {
21     mReturnShortcut = new QShortcut(Qt::Key_Return, p);   // TODO: what about Enter?
22     mReturnShortcut->setContext(Qt::WidgetWithChildrenShortcut);
23     QObject::connect(mReturnShortcut, &QShortcut::activated,
24                      p, [&]() { onReturnPressed(); });
25 }
26 
addButton(QPushButton * button,AbstractToolWidget::DefaultType defaultType)27 void AbstractToolWidgetPrivate::addButton(QPushButton* button, AbstractToolWidget::DefaultType defaultType)
28 {
29     button->setAutoDefault(true);
30     if (defaultType == AbstractToolWidget::Default) {
31         if (mDefaultButton) {
32             mDefaultButton->setDefault(false);
33         }
34 
35         // TODO: catch button deletion
36         mDefaultButton = button;
37         button->setDefault(true);
38     }
39 }
40 
onReturnPressed()41 void AbstractToolWidgetPrivate::onReturnPressed()
42 {
43     if (mDefaultButton) {
44         mDefaultButton->click();
45     }
46 }
47 
48 }
49