1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 03:15:32 +00:00
openmw-tes3mp/apps/opencs/view/widget/pushbutton.cpp

78 lines
1.8 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)";
switch (mType)
{
case Type_TopMode:
tooltip +=
"<p>(left click to change mode)";
break;
case Type_Mode:
tooltip +=
"<p>(left click to activate,"
"<br>shift-left click to activate and keep panel open)";
break;
}
2014-07-10 10:53:57 +00:00
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);
}
CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const std::string& tooltip,
2014-07-10 10:53:57 +00:00
QWidget *parent)
: QPushButton (icon, "", parent), mKeepOpen (false), mType (type)
2014-07-10 09:03:55 +00:00
{
setCheckable (type==Type_Mode);
2014-07-10 10:53:57 +00:00
setExtendedToolTip (tooltip);
}
CSVWidget::PushButton::PushButton (Type type, const std::string& tooltip, QWidget *parent)
: QPushButton (parent), mKeepOpen (false), mType (type)
{
setCheckable (type==Type_Mode);
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;
}