2014-07-10 09:03:55 +00:00
|
|
|
#include "pushbutton.hpp"
|
|
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
2016-07-26 00:49:09 +00:00
|
|
|
#include "../../model/prefs/state.hpp"
|
2016-07-29 20:02:46 +00:00
|
|
|
#include "../../model/prefs/shortcutmanager.hpp"
|
2016-07-26 00:49:09 +00:00
|
|
|
|
|
|
|
void CSVWidget::PushButton::processShortcuts()
|
|
|
|
{
|
2016-07-29 20:02:46 +00:00
|
|
|
mProcessedToolTip = CSMPrefs::State::get().getShortcutManager().processToolTip(mToolTip);
|
2016-07-26 00:49:09 +00:00
|
|
|
}
|
|
|
|
|
2014-08-01 07:50:49 +00:00
|
|
|
void CSVWidget::PushButton::setExtendedToolTip()
|
2014-07-10 10:53:57 +00:00
|
|
|
{
|
2016-07-26 00:49:09 +00:00
|
|
|
QString tooltip = mProcessedToolTip;
|
2014-07-10 10:53:57 +00:00
|
|
|
|
2014-07-13 12:21:50 +00:00
|
|
|
if (tooltip.isEmpty())
|
2014-07-10 10:53:57 +00:00
|
|
|
tooltip = "(Tool tip not implemented yet)";
|
|
|
|
|
2014-07-10 11:04:30 +00:00
|
|
|
switch (mType)
|
|
|
|
{
|
|
|
|
case Type_TopMode:
|
|
|
|
|
|
|
|
tooltip +=
|
|
|
|
"<p>(left click to change mode)";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2014-09-06 14:11:06 +00:00
|
|
|
case Type_TopAction:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2014-07-10 11:04:30 +00:00
|
|
|
case Type_Mode:
|
|
|
|
|
|
|
|
tooltip +=
|
|
|
|
"<p>(left click to activate,"
|
|
|
|
"<br>shift-left click to activate and keep panel open)";
|
|
|
|
|
2014-08-12 09:07:54 +00:00
|
|
|
break;
|
|
|
|
|
2014-07-31 11:05:08 +00:00
|
|
|
case Type_Toggle:
|
|
|
|
|
|
|
|
tooltip += "<p>(left click to ";
|
|
|
|
tooltip += isChecked() ? "disable" : "enable";
|
|
|
|
tooltip += "<p>shift-left click to ";
|
|
|
|
tooltip += isChecked() ? "disable" : "enable";
|
|
|
|
tooltip += " and keep panel open)";
|
|
|
|
|
2014-07-10 11:04:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-07-10 10:53:57 +00:00
|
|
|
|
2014-07-13 12:21:50 +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);
|
|
|
|
}
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
void CSVWidget::PushButton::keyReleaseEvent (QKeyEvent *event)
|
|
|
|
{
|
2014-08-01 07:50:49 +00:00
|
|
|
if (event->key()==Qt::Key_Space)
|
2014-07-10 09:32:20 +00:00
|
|
|
mKeepOpen = event->modifiers() & Qt::ShiftModifier;
|
2014-07-31 11:05:08 +00:00
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
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-13 12:21:50 +00:00
|
|
|
CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const QString& tooltip,
|
2014-07-10 10:53:57 +00:00
|
|
|
QWidget *parent)
|
2014-07-13 12:21:50 +00:00
|
|
|
: QPushButton (icon, "", parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
|
2014-07-10 09:03:55 +00:00
|
|
|
{
|
2014-11-27 07:59:21 +00:00
|
|
|
if (type==Type_Mode || type==Type_Toggle)
|
|
|
|
{
|
|
|
|
setCheckable (true);
|
|
|
|
connect (this, SIGNAL (toggled (bool)), this, SLOT (checkedStateChanged (bool)));
|
|
|
|
}
|
2014-07-31 11:05:08 +00:00
|
|
|
setCheckable (type==Type_Mode || type==Type_Toggle);
|
2016-07-26 00:49:09 +00:00
|
|
|
processShortcuts();
|
2014-08-01 07:50:49 +00:00
|
|
|
setExtendedToolTip();
|
2016-07-26 00:49:09 +00:00
|
|
|
|
|
|
|
connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
|
|
|
|
this, SLOT (settingChanged (const CSMPrefs::Setting *)));
|
2014-07-10 09:44:01 +00:00
|
|
|
}
|
|
|
|
|
2014-07-13 12:21:50 +00:00
|
|
|
CSVWidget::PushButton::PushButton (Type type, const QString& tooltip, QWidget *parent)
|
|
|
|
: QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
|
2014-07-10 09:44:01 +00:00
|
|
|
{
|
2014-07-31 11:05:08 +00:00
|
|
|
setCheckable (type==Type_Mode || type==Type_Toggle);
|
2016-07-26 00:49:09 +00:00
|
|
|
processShortcuts();
|
2014-08-01 07:50:49 +00:00
|
|
|
setExtendedToolTip();
|
2014-07-10 09:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CSVWidget::PushButton::hasKeepOpen() const
|
|
|
|
{
|
|
|
|
return mKeepOpen;
|
2014-07-13 12:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CSVWidget::PushButton::getBaseToolTip() const
|
|
|
|
{
|
2016-07-26 00:49:09 +00:00
|
|
|
return mProcessedToolTip;
|
2014-09-07 11:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSVWidget::PushButton::Type CSVWidget::PushButton::getType() const
|
|
|
|
{
|
|
|
|
return mType;
|
2014-11-27 07:59:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVWidget::PushButton::checkedStateChanged (bool checked)
|
|
|
|
{
|
|
|
|
setExtendedToolTip();
|
2015-03-11 14:54:45 +00:00
|
|
|
}
|
2016-07-26 00:49:09 +00:00
|
|
|
|
|
|
|
void CSVWidget::PushButton::settingChanged (const CSMPrefs::Setting *setting)
|
|
|
|
{
|
|
|
|
if (setting->getParent()->getKey() == "Key Bindings")
|
|
|
|
{
|
|
|
|
processShortcuts();
|
|
|
|
setExtendedToolTip();
|
|
|
|
}
|
|
|
|
}
|