1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

Added methods to keep text mentioning shortcuts up to date,

fixed potential issue with widget relationship tracking,
hopefully got rid of signed/unsigned errors (Qt4/5 issue)
This commit is contained in:
Aesylwinn 2016-07-25 20:49:09 -04:00
parent f251c3867d
commit 051aec2729
11 changed files with 168 additions and 17 deletions

View file

@ -2,6 +2,7 @@
#include <cassert> #include <cassert>
#include <QAction>
#include <QWidget> #include <QWidget>
#include "state.hpp" #include "state.hpp"
@ -19,6 +20,7 @@ namespace CSMPrefs
, mLastPos(0) , mLastPos(0)
, mActivationStatus(AS_Inactive) , mActivationStatus(AS_Inactive)
, mModifierStatus(false) , mModifierStatus(false)
, mAction(0)
{ {
assert (parent); assert (parent);
@ -38,6 +40,7 @@ namespace CSMPrefs
, mLastPos(0) , mLastPos(0)
, mActivationStatus(AS_Inactive) , mActivationStatus(AS_Inactive)
, mModifierStatus(false) , mModifierStatus(false)
, mAction(0)
{ {
assert (parent); assert (parent);
@ -107,6 +110,9 @@ namespace CSMPrefs
mSequence = sequence; mSequence = sequence;
mCurrentPos = 0; mCurrentPos = 0;
mLastPos = sequence.count() - 1; mLastPos = sequence.count() - 1;
if (mAction)
mAction->setText(mActionText + "\t" + toString());
} }
void Shortcut::setModifier(int modifier) void Shortcut::setModifier(int modifier)
@ -129,6 +135,24 @@ namespace CSMPrefs
mModifierStatus = status; mModifierStatus = status;
} }
void Shortcut::associateAction(QAction* action)
{
if (mAction)
{
disconnect(this, SLOT(actionDeleted()));
}
mAction = action;
if (mAction)
{
mActionText = mAction->text();
mAction->setText(mActionText + "\t" + toString());
connect(mAction, SIGNAL(destroyed()), this, SLOT(actionDeleted()));
}
}
void Shortcut::signalActivated(bool state) void Shortcut::signalActivated(bool state)
{ {
emit activated(state); emit activated(state);
@ -152,4 +176,9 @@ namespace CSMPrefs
{ {
return QString(State::get().getShortcutManager().sequenceToString(std::make_pair(mSequence, mModifier)).data()); return QString(State::get().getShortcutManager().sequenceToString(std::make_pair(mSequence, mModifier)).data());
} }
void Shortcut::actionDeleted()
{
mAction = 0;
}
} }

View file

@ -7,6 +7,7 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
class QAction;
class QWidget; class QWidget;
namespace CSMPrefs namespace CSMPrefs
@ -64,6 +65,9 @@ namespace CSMPrefs
void setActivationStatus(ActivationStatus status); void setActivationStatus(ActivationStatus status);
void setModifierStatus(bool status); void setModifierStatus(bool status);
/// Appends the sequence to the QAction text, also keeps it up to date
void associateAction(QAction* action);
// Workaround for Qt4 signals being "protected" // Workaround for Qt4 signals being "protected"
void signalActivated(bool state); void signalActivated(bool state);
void signalActivated(); void signalActivated();
@ -88,6 +92,13 @@ namespace CSMPrefs
ActivationStatus mActivationStatus; ActivationStatus mActivationStatus;
bool mModifierStatus; bool mModifierStatus;
QAction* mAction;
QString mActionText;
private slots:
void actionDeleted();
signals: signals:
/// Triggered when the shortcut is activated or deactivated; can be determined from \p state /// Triggered when the shortcut is activated or deactivated; can be determined from \p state

View file

@ -137,6 +137,7 @@ namespace CSMPrefs
if (parentIt != mWidgetShortcuts.end()) if (parentIt != mWidgetShortcuts.end())
{ {
mChildParentRelations.insert(std::make_pair(widget, parent)); mChildParentRelations.insert(std::make_pair(widget, parent));
updateParent(parent);
break; break;
} }

View file

@ -92,7 +92,7 @@ namespace CSMPrefs
std::string output; std::string output;
// KeySequence // KeySequence
for (int i = 0; i < data.first.count(); ++i) for (int i = 0; i < (int)data.first.count(); ++i)
{ {
if (data.first[i] & ModMask) if (data.first[i] & ModMask)
{ {

View file

@ -64,6 +64,7 @@ void CSVDoc::View::setupFileMenu()
file->addAction (mSave); file->addAction (mSave);
CSMPrefs::Shortcut* saveShortcut = new CSMPrefs::Shortcut("document-save", this); CSMPrefs::Shortcut* saveShortcut = new CSMPrefs::Shortcut("document-save", this);
saveShortcut->associateAction(mSave);
connect (saveShortcut, SIGNAL(activated()), this, SLOT(save())); connect (saveShortcut, SIGNAL(activated()), this, SLOT(save()));
mVerify = new QAction (tr ("&Verify"), this); mVerify = new QAction (tr ("&Verify"), this);

View file

@ -26,7 +26,8 @@ namespace CSVRender
void OrbitCameraMode::activate(CSVWidget::SceneToolbar* toolbar) void OrbitCameraMode::activate(CSVWidget::SceneToolbar* toolbar)
{ {
mCenterOnSelection = new QAction("Center on selected object\t" + mCenterShortcut->toString(), this); mCenterOnSelection = new QAction("Center on selected object", this);
mCenterShortcut->associateAction(mCenterOnSelection);
connect(mCenterOnSelection, SIGNAL(triggered()), this, SLOT(centerSelection())); connect(mCenterOnSelection, SIGNAL(triggered()), this, SLOT(centerSelection()));
mCenterShortcut->enable(true); mCenterShortcut->enable(true);
@ -34,6 +35,7 @@ namespace CSVRender
void OrbitCameraMode::deactivate(CSVWidget::SceneToolbar* toolbar) void OrbitCameraMode::deactivate(CSVWidget::SceneToolbar* toolbar)
{ {
mCenterShortcut->associateAction(0);
mCenterShortcut->enable(false); mCenterShortcut->enable(false);
} }

View file

@ -163,30 +163,32 @@ CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
/// \todo consider user-defined button-mapping /// \todo consider user-defined button-mapping
tool->addButton (":scenetoolbar/1st-person", "1st", tool->addButton (":scenetoolbar/1st-person", "1st",
"First Person" "First Person"
"<ul><li>Mouse-Look while holding the left button</li>" "<ul><li>Camera is held upright</li>"
"<li>WASD movement keys</li>" "<li>Mouse-Look while holding {scene-navi-primary}</li>"
"<li>Movement keys: {free-forward}(forward), {free-left}(left), {free-backward}(back), {free-right}(right)</li>"
"<li>Strafing (also vertically) by holding {scene-navi-secondary}</li>"
"<li>Mouse wheel moves the camera forward/backward</li>" "<li>Mouse wheel moves the camera forward/backward</li>"
"<li>Strafing (also vertically) by holding the left mouse button and control</li>" "<li>Hold {free-forward:mod} to speed up movement</li>"
"<li>Camera is held upright</li>"
"<li>Hold shift to speed up movement</li>"
"</ul>"); "</ul>");
tool->addButton (":scenetoolbar/free-camera", "free", tool->addButton (":scenetoolbar/free-camera", "free",
"Free Camera" "Free Camera"
"<ul><li>Mouse-Look while holding the left button</li>" "<ul><li>Mouse-Look while holding {scene-navi-primary}</li>"
"<li>Strafing (also vertically) via WASD or by holding the left mouse button and control</li>" "<li>Movement keys: {free-forward}(forward), {free-left}(left), {free-backward}(back), {free-right}(right)</li>"
"<li>Roll camera with {free-roll-left} and {free-roll-right} keys</li>"
"<li>Strafing (also vertically) by holding {scene-navi-secondary}</li>"
"<li>Mouse wheel moves the camera forward/backward</li>" "<li>Mouse wheel moves the camera forward/backward</li>"
"<li>Roll camera with Q and E keys</li>" "<li>Hold {free-forward:mod} to speed up movement</li>"
"<li>Hold shift to speed up movement</li>"
"</ul>"); "</ul>");
tool->addButton( tool->addButton(
new CSVRender::OrbitCameraMode(this, QIcon(":scenetoolbar/orbiting-camera"), new CSVRender::OrbitCameraMode(this, QIcon(":scenetoolbar/orbiting-camera"),
"Orbiting Camera" "Orbiting Camera"
"<ul><li>Always facing the centre point</li>" "<ul><li>Always facing the centre point</li>"
"<li>Rotate around the centre point via WASD or by moving the mouse while holding the left button</li>" "<li>Rotate around the centre point via {orbit-up}, {orbit-left}, {orbit-down}, {orbit-right} or by moving "
"the mouse while holding {scene-navi-primary}</li>"
"<li>Roll camera with {orbit-roll-left} and {orbit-roll-right} keys</li>"
"<li>Strafing (also vertically) by holding {scene-navi-secondary} (includes relocation of the centre point)</li>"
"<li>Mouse wheel moves camera away or towards centre point but can not pass through it</li>" "<li>Mouse wheel moves camera away or towards centre point but can not pass through it</li>"
"<li>Roll camera with Q and E keys</li>" "<li>Hold {orbit-up:mod} to speed up movement</li>"
"<li>Strafing (also vertically) by holding the left mouse button and control (includes relocation of the centre point)</li>"
"<li>Hold shift to speed up movement</li>"
"</ul>", tool), "</ul>", tool),
"orbit"); "orbit");

View file

@ -3,9 +3,75 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include "../../model/prefs/state.hpp"
void CSVWidget::PushButton::processShortcuts()
{
const QChar SequenceStart = '{';
const QChar SequenceEnd = '}';
const QString ModifierSequence = QString::fromUtf8(":mod");
const QChar SettingSeparator = ';';
QStringList substrings;
int prevIndex = 0;
int startIndex = mToolTip.indexOf(SequenceStart);
int endIndex = (startIndex != -1) ? mToolTip.indexOf(SequenceEnd, startIndex) : -1;
// Process every valid shortcut escape sequence
while (startIndex != -1 && endIndex != -1)
{
int count = startIndex - prevIndex;
if (count > 0)
{
substrings.push_back(mToolTip.mid(prevIndex, count));
}
// Find sequence name
count = endIndex - startIndex - 1;
if (count > 0)
{
// Check if looking for modifier
int separatorIndex = mToolTip.indexOf(ModifierSequence, startIndex);
if (separatorIndex != -1 && separatorIndex < endIndex)
{
count = separatorIndex - startIndex - 1;
QString settingName = mToolTip.mid(startIndex+1, count);
QString value = QString::fromUtf8(
CSMPrefs::State::get()["Key Bindings"][settingName.toUtf8().data()].toString().c_str());
substrings.push_back(value.right(value.size() - value.indexOf(SettingSeparator) - 1));
}
else
{
QString settingName = mToolTip.mid(startIndex+1, count);
QString value = QString::fromUtf8(
CSMPrefs::State::get()["Key Bindings"][settingName.toUtf8().data()].toString().c_str());
// Don't want modifier
substrings.push_back(value.left(value.indexOf(SettingSeparator)));
}
prevIndex = endIndex + 1;
}
startIndex = mToolTip.indexOf(SequenceStart, endIndex);
endIndex = (startIndex != -1) ? mToolTip.indexOf(SequenceEnd, startIndex) : -1;
}
if (prevIndex < mToolTip.size())
{
substrings.push_back(mToolTip.mid(prevIndex));
}
mProcessedToolTip = substrings.join("");
}
void CSVWidget::PushButton::setExtendedToolTip() void CSVWidget::PushButton::setExtendedToolTip()
{ {
QString tooltip = mToolTip; QString tooltip = mProcessedToolTip;
if (tooltip.isEmpty()) if (tooltip.isEmpty())
tooltip = "(Tool tip not implemented yet)"; tooltip = "(Tool tip not implemented yet)";
@ -77,13 +143,18 @@ CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const QString&
connect (this, SIGNAL (toggled (bool)), this, SLOT (checkedStateChanged (bool))); connect (this, SIGNAL (toggled (bool)), this, SLOT (checkedStateChanged (bool)));
} }
setCheckable (type==Type_Mode || type==Type_Toggle); setCheckable (type==Type_Mode || type==Type_Toggle);
processShortcuts();
setExtendedToolTip(); setExtendedToolTip();
connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
this, SLOT (settingChanged (const CSMPrefs::Setting *)));
} }
CSVWidget::PushButton::PushButton (Type type, const QString& tooltip, QWidget *parent) CSVWidget::PushButton::PushButton (Type type, const QString& tooltip, QWidget *parent)
: QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip) : QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
{ {
setCheckable (type==Type_Mode || type==Type_Toggle); setCheckable (type==Type_Mode || type==Type_Toggle);
processShortcuts();
setExtendedToolTip(); setExtendedToolTip();
} }
@ -94,7 +165,7 @@ bool CSVWidget::PushButton::hasKeepOpen() const
QString CSVWidget::PushButton::getBaseToolTip() const QString CSVWidget::PushButton::getBaseToolTip() const
{ {
return mToolTip; return mProcessedToolTip;
} }
CSVWidget::PushButton::Type CSVWidget::PushButton::getType() const CSVWidget::PushButton::Type CSVWidget::PushButton::getType() const
@ -106,3 +177,12 @@ void CSVWidget::PushButton::checkedStateChanged (bool checked)
{ {
setExtendedToolTip(); setExtendedToolTip();
} }
void CSVWidget::PushButton::settingChanged (const CSMPrefs::Setting *setting)
{
if (setting->getParent()->getKey() == "Key Bindings")
{
processShortcuts();
setExtendedToolTip();
}
}

View file

@ -3,6 +3,11 @@
#include <QPushButton> #include <QPushButton>
namespace CSMPrefs
{
class Setting;
}
namespace CSVWidget namespace CSVWidget
{ {
class PushButton : public QPushButton class PushButton : public QPushButton
@ -24,9 +29,12 @@ namespace CSVWidget
bool mKeepOpen; bool mKeepOpen;
Type mType; Type mType;
QString mToolTip; QString mToolTip;
QString mProcessedToolTip;
private: private:
// Uses {, :, and } as escape sequences for looking up shortcut settings
void processShortcuts();
void setExtendedToolTip(); void setExtendedToolTip();
protected: protected:
@ -57,6 +65,7 @@ namespace CSVWidget
private slots: private slots:
void checkedStateChanged (bool checked); void checkedStateChanged (bool checked);
void settingChanged (const CSMPrefs::Setting *setting);
}; };
} }

View file

@ -5,6 +5,7 @@
#include <QSignalMapper> #include <QSignalMapper>
#include <QMenu> #include <QMenu>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QEvent>
#include "scenetoolbar.hpp" #include "scenetoolbar.hpp"
#include "modebutton.hpp" #include "modebutton.hpp"
@ -133,6 +134,16 @@ void CSVWidget::SceneToolMode::setButton (const std::string& id)
} }
} }
bool CSVWidget::SceneToolMode::event(QEvent* event)
{
if (event->type() == QEvent::ToolTip)
{
adjustToolTip(mCurrent);
}
return SceneTool::event(event);
}
void CSVWidget::SceneToolMode::selected() void CSVWidget::SceneToolMode::selected()
{ {
std::map<ModeButton *, std::string>::iterator iter = std::map<ModeButton *, std::string>::iterator iter =

View file

@ -7,6 +7,7 @@
class QHBoxLayout; class QHBoxLayout;
class QMenu; class QMenu;
class QEvent;
namespace CSVWidget namespace CSVWidget
{ {
@ -43,6 +44,10 @@ namespace CSVWidget
void setButton (std::map<ModeButton *, std::string>::iterator iter); void setButton (std::map<ModeButton *, std::string>::iterator iter);
protected:
bool event(QEvent* event);
public: public:
SceneToolMode (SceneToolbar *parent, const QString& toolTip); SceneToolMode (SceneToolbar *parent, const QString& toolTip);