forked from mirror/openmw-tes3mp
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:
parent
f251c3867d
commit
051aec2729
11 changed files with 168 additions and 17 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#include <QAction>
|
||||
#include <QWidget>
|
||||
|
||||
#include "state.hpp"
|
||||
|
@ -19,6 +20,7 @@ namespace CSMPrefs
|
|||
, mLastPos(0)
|
||||
, mActivationStatus(AS_Inactive)
|
||||
, mModifierStatus(false)
|
||||
, mAction(0)
|
||||
{
|
||||
assert (parent);
|
||||
|
||||
|
@ -38,6 +40,7 @@ namespace CSMPrefs
|
|||
, mLastPos(0)
|
||||
, mActivationStatus(AS_Inactive)
|
||||
, mModifierStatus(false)
|
||||
, mAction(0)
|
||||
{
|
||||
assert (parent);
|
||||
|
||||
|
@ -107,6 +110,9 @@ namespace CSMPrefs
|
|||
mSequence = sequence;
|
||||
mCurrentPos = 0;
|
||||
mLastPos = sequence.count() - 1;
|
||||
|
||||
if (mAction)
|
||||
mAction->setText(mActionText + "\t" + toString());
|
||||
}
|
||||
|
||||
void Shortcut::setModifier(int modifier)
|
||||
|
@ -129,6 +135,24 @@ namespace CSMPrefs
|
|||
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)
|
||||
{
|
||||
emit activated(state);
|
||||
|
@ -152,4 +176,9 @@ namespace CSMPrefs
|
|||
{
|
||||
return QString(State::get().getShortcutManager().sequenceToString(std::make_pair(mSequence, mModifier)).data());
|
||||
}
|
||||
|
||||
void Shortcut::actionDeleted()
|
||||
{
|
||||
mAction = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class QAction;
|
||||
class QWidget;
|
||||
|
||||
namespace CSMPrefs
|
||||
|
@ -64,6 +65,9 @@ namespace CSMPrefs
|
|||
void setActivationStatus(ActivationStatus 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"
|
||||
void signalActivated(bool state);
|
||||
void signalActivated();
|
||||
|
@ -88,6 +92,13 @@ namespace CSMPrefs
|
|||
ActivationStatus mActivationStatus;
|
||||
bool mModifierStatus;
|
||||
|
||||
QAction* mAction;
|
||||
QString mActionText;
|
||||
|
||||
private slots:
|
||||
|
||||
void actionDeleted();
|
||||
|
||||
signals:
|
||||
|
||||
/// Triggered when the shortcut is activated or deactivated; can be determined from \p state
|
||||
|
|
|
@ -137,6 +137,7 @@ namespace CSMPrefs
|
|||
if (parentIt != mWidgetShortcuts.end())
|
||||
{
|
||||
mChildParentRelations.insert(std::make_pair(widget, parent));
|
||||
updateParent(parent);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace CSMPrefs
|
|||
std::string output;
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
|
|
@ -64,6 +64,7 @@ void CSVDoc::View::setupFileMenu()
|
|||
file->addAction (mSave);
|
||||
|
||||
CSMPrefs::Shortcut* saveShortcut = new CSMPrefs::Shortcut("document-save", this);
|
||||
saveShortcut->associateAction(mSave);
|
||||
connect (saveShortcut, SIGNAL(activated()), this, SLOT(save()));
|
||||
|
||||
mVerify = new QAction (tr ("&Verify"), this);
|
||||
|
|
|
@ -26,7 +26,8 @@ namespace CSVRender
|
|||
|
||||
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()));
|
||||
|
||||
mCenterShortcut->enable(true);
|
||||
|
@ -34,6 +35,7 @@ namespace CSVRender
|
|||
|
||||
void OrbitCameraMode::deactivate(CSVWidget::SceneToolbar* toolbar)
|
||||
{
|
||||
mCenterShortcut->associateAction(0);
|
||||
mCenterShortcut->enable(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -163,30 +163,32 @@ CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
|
|||
/// \todo consider user-defined button-mapping
|
||||
tool->addButton (":scenetoolbar/1st-person", "1st",
|
||||
"First Person"
|
||||
"<ul><li>Mouse-Look while holding the left button</li>"
|
||||
"<li>WASD movement keys</li>"
|
||||
"<ul><li>Camera is held upright</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>Strafing (also vertically) by holding the left mouse button and control</li>"
|
||||
"<li>Camera is held upright</li>"
|
||||
"<li>Hold shift to speed up movement</li>"
|
||||
"<li>Hold {free-forward:mod} to speed up movement</li>"
|
||||
"</ul>");
|
||||
tool->addButton (":scenetoolbar/free-camera", "free",
|
||||
"Free Camera"
|
||||
"<ul><li>Mouse-Look while holding the left button</li>"
|
||||
"<li>Strafing (also vertically) via WASD or by holding the left mouse button and control</li>"
|
||||
"<ul><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>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>Roll camera with Q and E keys</li>"
|
||||
"<li>Hold shift to speed up movement</li>"
|
||||
"<li>Hold {free-forward:mod} to speed up movement</li>"
|
||||
"</ul>");
|
||||
tool->addButton(
|
||||
new CSVRender::OrbitCameraMode(this, QIcon(":scenetoolbar/orbiting-camera"),
|
||||
"Orbiting Camera"
|
||||
"<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>Roll camera with Q and E keys</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>"
|
||||
"<li>Hold {orbit-up:mod} to speed up movement</li>"
|
||||
"</ul>", tool),
|
||||
"orbit");
|
||||
|
||||
|
|
|
@ -3,9 +3,75 @@
|
|||
#include <QMouseEvent>
|
||||
#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()
|
||||
{
|
||||
QString tooltip = mToolTip;
|
||||
QString tooltip = mProcessedToolTip;
|
||||
|
||||
if (tooltip.isEmpty())
|
||||
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)));
|
||||
}
|
||||
setCheckable (type==Type_Mode || type==Type_Toggle);
|
||||
processShortcuts();
|
||||
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)
|
||||
: QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
|
||||
{
|
||||
setCheckable (type==Type_Mode || type==Type_Toggle);
|
||||
processShortcuts();
|
||||
setExtendedToolTip();
|
||||
}
|
||||
|
||||
|
@ -94,7 +165,7 @@ bool CSVWidget::PushButton::hasKeepOpen() const
|
|||
|
||||
QString CSVWidget::PushButton::getBaseToolTip() const
|
||||
{
|
||||
return mToolTip;
|
||||
return mProcessedToolTip;
|
||||
}
|
||||
|
||||
CSVWidget::PushButton::Type CSVWidget::PushButton::getType() const
|
||||
|
@ -106,3 +177,12 @@ void CSVWidget::PushButton::checkedStateChanged (bool checked)
|
|||
{
|
||||
setExtendedToolTip();
|
||||
}
|
||||
|
||||
void CSVWidget::PushButton::settingChanged (const CSMPrefs::Setting *setting)
|
||||
{
|
||||
if (setting->getParent()->getKey() == "Key Bindings")
|
||||
{
|
||||
processShortcuts();
|
||||
setExtendedToolTip();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include <QPushButton>
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class Setting;
|
||||
}
|
||||
|
||||
namespace CSVWidget
|
||||
{
|
||||
class PushButton : public QPushButton
|
||||
|
@ -24,9 +29,12 @@ namespace CSVWidget
|
|||
bool mKeepOpen;
|
||||
Type mType;
|
||||
QString mToolTip;
|
||||
QString mProcessedToolTip;
|
||||
|
||||
private:
|
||||
|
||||
// Uses {, :, and } as escape sequences for looking up shortcut settings
|
||||
void processShortcuts();
|
||||
void setExtendedToolTip();
|
||||
|
||||
protected:
|
||||
|
@ -57,6 +65,7 @@ namespace CSVWidget
|
|||
private slots:
|
||||
|
||||
void checkedStateChanged (bool checked);
|
||||
void settingChanged (const CSMPrefs::Setting *setting);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QSignalMapper>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QEvent>
|
||||
|
||||
#include "scenetoolbar.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()
|
||||
{
|
||||
std::map<ModeButton *, std::string>::iterator iter =
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
class QHBoxLayout;
|
||||
class QMenu;
|
||||
class QEvent;
|
||||
|
||||
namespace CSVWidget
|
||||
{
|
||||
|
@ -43,6 +44,10 @@ namespace CSVWidget
|
|||
|
||||
void setButton (std::map<ModeButton *, std::string>::iterator iter);
|
||||
|
||||
protected:
|
||||
|
||||
bool event(QEvent* event);
|
||||
|
||||
public:
|
||||
|
||||
SceneToolMode (SceneToolbar *parent, const QString& toolTip);
|
||||
|
|
Loading…
Reference in a new issue