Warning, file /graphics/krita/libs/ui/input/config/kis_mouse_input_editor.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * This file is part of the KDE project
0003  * SPDX-FileCopyrightText: 2013 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "kis_mouse_input_editor.h"
0009 
0010 #include <QWidgetAction>
0011 #include <QMenu>
0012 #include <QTimer>
0013 
0014 #include "kis_icon_utils.h"
0015 
0016 #include "ui_kis_mouse_input_editor.h"
0017 
0018 class KisMouseInputEditor::Private
0019 {
0020 public:
0021     Private() { }
0022 
0023     Ui::KisMouseInputEditor *ui {nullptr};
0024 };
0025 
0026 KisMouseInputEditor::KisMouseInputEditor(QWidget *parent)
0027     : QPushButton(parent), d(new Private)
0028 {
0029     QWidget *popup = new QWidget();
0030 
0031     d->ui = new Ui::KisMouseInputEditor;
0032     d->ui->setupUi(popup);
0033     d->ui->mouseButton->setType(KisInputButton::MouseType);
0034 
0035     d->ui->clearModifiersButton->setIcon(KisIconUtils::loadIcon("edit-clear"));
0036     d->ui->clearMouseButton->setIcon(KisIconUtils::loadIcon("edit-clear"));
0037 
0038     QWidgetAction *action = new QWidgetAction(this);
0039     action->setDefaultWidget(popup);
0040 
0041     QMenu *menu = new QMenu(this);
0042     menu->addAction(action);
0043     setMenu(menu);
0044 
0045     QTimer::singleShot(0, this, SLOT(showMenu()));
0046 
0047     connect(d->ui->mouseButton, SIGNAL(dataChanged()), SLOT(updateLabel()));
0048     connect(d->ui->modifiersButton, SIGNAL(dataChanged()), SLOT(updateLabel()));
0049     connect(d->ui->clearMouseButton, SIGNAL(clicked(bool)), d->ui->mouseButton, SLOT(clear()));
0050     connect(d->ui->clearModifiersButton, SIGNAL(clicked(bool)), d->ui->modifiersButton, SLOT(clear()));
0051 }
0052 
0053 KisMouseInputEditor::~KisMouseInputEditor()
0054 {
0055     delete d->ui;
0056     delete d;
0057 }
0058 
0059 QList< Qt::Key > KisMouseInputEditor::keys() const
0060 {
0061     return d->ui->modifiersButton->keys();
0062 }
0063 
0064 void KisMouseInputEditor::setKeys(const QList< Qt::Key > &newKeys)
0065 {
0066     d->ui->modifiersButton->setKeys(newKeys);
0067     updateLabel();
0068 }
0069 
0070 Qt::MouseButtons KisMouseInputEditor::buttons() const
0071 {
0072     return d->ui->mouseButton->buttons();
0073 }
0074 
0075 void KisMouseInputEditor::setButtons(Qt::MouseButtons newButtons)
0076 {
0077     d->ui->mouseButton->setButtons(newButtons);
0078     updateLabel();
0079 }
0080 
0081 void KisMouseInputEditor::updateLabel()
0082 {
0083     setText(KisShortcutConfiguration::buttonsInputToText(
0084         d->ui->modifiersButton->keys(),
0085         d->ui->mouseButton->buttons()));
0086 }