Commit e1dc37ed authored by José Luis Vergara's avatar José Luis Vergara
Browse files

Create KisToolButton, a sublass of QToolButton to bypass a bug in tablet support

o Add the class to CMakeLists.txt
o Document it
o Promote bnAdd in WdgLayerBox from QToolButton to KisToolButton

BUG:277186
parent a048cd2c
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>219</width>
<width>287</width>
<height>348</height>
</rect>
</property>
......@@ -72,7 +72,7 @@
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="bnAdd">
<widget class="KisToolButton" name="bnAdd">
<property name="minimumSize">
<size>
<width>41</width>
......@@ -269,6 +269,11 @@
<extends></extends>
<header location="global">KoDocumentSectionView.h</header>
</customwidget>
<customwidget>
<class>KisToolButton</class>
<extends>QToolButton</extends>
<header>kis_tool_button.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
......@@ -167,6 +167,7 @@ set(kritaui_LIB_SRCS
widgets/squeezedcombobox.cpp
widgets/kis_categorized_list_view.cpp
widgets/kis_widget_chooser.cpp
widgets/kis_tool_button.cpp
# widgets/kis_light_source.cpp
# widgets/kis_light_stage.cpp
)
......
/*
* Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_tool_button.h"
#include <QMouseEvent>
#include <QStyleOptionToolButton>
KisToolButton::KisToolButton(QWidget *parent) :
QToolButton(parent)
{
m_tabletContact = false;
}
void KisToolButton::mousePressEvent(QMouseEvent *e)
{
QStyleOptionToolButton opt;
initStyleOption(&opt);
QRect popupr = style()->subControlRect(QStyle::CC_ToolButton, &opt,
QStyle::SC_ToolButtonMenu, this);
if (popupr.isValid() && !popupr.contains(e->pos())) {
QToolButton::mousePressEvent(e);
} else {
m_tabletContact = true;
}
}
void KisToolButton::mouseReleaseEvent(QMouseEvent *e)
{
if (m_tabletContact) {
QToolButton::mousePressEvent(e);
} else {
QToolButton::mouseReleaseEvent(e);
}
m_tabletContact = false;
}
\ No newline at end of file
/*
* Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_TOOL_BUTTON_H
#define KIS_TOOL_BUTTON_H
#include <QToolButton>
#include <krita_export.h>
/** This class exists to work around a bug in QToolButton when in
* MenuPopupButton mode. The correct (mouse) behavior is to display
* the menu with the first click, and let the user choose an item with
* the next click. The buggy behavior presented by the tablet is to
* present the menu and immediately select an item when the user
* performs a stylus tip click. This workaround solves this.
*/
class KRITAUI_EXPORT KisToolButton : public QToolButton
{
Q_OBJECT
public:
explicit KisToolButton(QWidget *parent = 0);
protected:
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseReleaseEvent(QMouseEvent *e);
private:
bool m_tabletContact;
};
#endif // KIS_TOOL_BUTTON_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment