1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 22:23:52 +00:00
openmw/apps/opencs/view/widget/pushbutton.cpp

64 lines
1.6 KiB
C++
Raw Normal View History

2014-07-10 09:03:55 +00:00
#include "pushbutton.hpp"
#include <QMouseEvent>
#include <QKeyEvent>
2014-07-10 10:53:57 +00:00
void CSVWidget::PushButton::setExtendedToolTip (const std::string& text)
{
std::string tooltip = text;
if (tooltip.empty())
tooltip = "(Tool tip not implemented yet)";
if (!mPush)
tooltip +=
"<p>(left click to activate,<br>shift-left click to activate and keep panel open)";
setToolTip (QString::fromUtf8 (tooltip.c_str()));
}
2014-07-10 09:03:55 +00:00
void CSVWidget::PushButton::keyPressEvent (QKeyEvent *event)
{
if (event->key()!=Qt::Key_Shift)
mKeepOpen = false;
QPushButton::keyPressEvent (event);
}
void CSVWidget::PushButton::keyReleaseEvent (QKeyEvent *event)
{
if (event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter)
{
mKeepOpen = event->modifiers() & Qt::ShiftModifier;
emit clicked();
}
QPushButton::keyReleaseEvent (event);
}
2014-07-10 09:03:55 +00:00
void CSVWidget::PushButton::mouseReleaseEvent (QMouseEvent *event)
{
mKeepOpen = event->button()==Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier);
QPushButton::mouseReleaseEvent (event);
}
2014-07-10 10:53:57 +00:00
CSVWidget::PushButton::PushButton (const QIcon& icon, bool push, const std::string& tooltip,
QWidget *parent)
: QPushButton (icon, "", parent), mKeepOpen (false), mPush (push)
2014-07-10 09:03:55 +00:00
{
setCheckable (!push);
2014-07-10 10:53:57 +00:00
setExtendedToolTip (tooltip);
}
2014-07-10 10:53:57 +00:00
CSVWidget::PushButton::PushButton (bool push, const std::string& tooltip, QWidget *parent)
: QPushButton (parent), mKeepOpen (false), mPush (push)
{
setCheckable (!push);
2014-07-10 10:53:57 +00:00
setExtendedToolTip (tooltip);
2014-07-10 09:03:55 +00:00
}
bool CSVWidget::PushButton::hasKeepOpen() const
{
return mKeepOpen;
}