1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 15:39:02 +00:00
OpenMW/apps/opencs/view/widget/pushbutton.cpp

83 lines
1.9 KiB
C++
Raw Normal View History

2014-07-10 09:03:55 +00:00
#include "pushbutton.hpp"
#include <QMouseEvent>
#include <QKeyEvent>
void CSVWidget::PushButton::setExtendedToolTip (const QString& text)
2014-07-10 10:53:57 +00:00
{
QString tooltip = text;
2014-07-10 10:53:57 +00:00
if (tooltip.isEmpty())
2014-07-10 10:53:57 +00:00
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 (tooltip);
2014-07-10 10:53:57 +00:00
}
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 QString& tooltip,
2014-07-10 10:53:57 +00:00
QWidget *parent)
: QPushButton (icon, "", parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
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 QString& tooltip, QWidget *parent)
: QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
{
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;
}
QString CSVWidget::PushButton::getBaseToolTip() const
{
return mToolTip;
2014-07-10 09:03:55 +00:00
}