forked from mirror/openmw-tes3mp
Move tool tip processing to ShortcutManager,
Process cell arrow tooltip, Fix cell arrows not being added when cell is added
This commit is contained in:
parent
d7a83d80a2
commit
2f97d6cffb
6 changed files with 91 additions and 67 deletions
|
@ -255,6 +255,74 @@ namespace CSMPrefs
|
|||
}
|
||||
}
|
||||
|
||||
QString ShortcutManager::processToolTip(const QString& toolTip) const
|
||||
{
|
||||
const QChar SequenceStart = '{';
|
||||
const QChar SequenceEnd = '}';
|
||||
const QString ModifierSequence = QString::fromUtf8(":mod");
|
||||
|
||||
QStringList substrings;
|
||||
|
||||
int prevIndex = 0;
|
||||
int startIndex = toolTip.indexOf(SequenceStart);
|
||||
int endIndex = (startIndex != -1) ? toolTip.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(toolTip.mid(prevIndex, count));
|
||||
}
|
||||
|
||||
// Find sequence name
|
||||
startIndex += 1; // '{' character
|
||||
count = endIndex - startIndex;
|
||||
if (count > 0)
|
||||
{
|
||||
// Check if looking for modifier
|
||||
int separatorIndex = toolTip.indexOf(ModifierSequence, startIndex);
|
||||
if (separatorIndex != -1 && separatorIndex < endIndex)
|
||||
{
|
||||
count = separatorIndex - startIndex;
|
||||
|
||||
QString settingName = toolTip.mid(startIndex, count);
|
||||
|
||||
QKeySequence ignored;
|
||||
int modifier = 0;
|
||||
getSequence(settingName.toUtf8().data(), ignored, modifier);
|
||||
|
||||
QString value = QString::fromUtf8(convertToString(modifier).c_str());
|
||||
substrings.push_back(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString settingName = toolTip.mid(startIndex, count);
|
||||
|
||||
QKeySequence sequence;
|
||||
int ignored = 0;
|
||||
getSequence(settingName.toUtf8().data(), sequence, ignored);
|
||||
|
||||
QString value = QString::fromUtf8(convertToString(sequence).c_str());
|
||||
substrings.push_back(value);
|
||||
}
|
||||
|
||||
prevIndex = endIndex + 1; // '}' character
|
||||
}
|
||||
|
||||
startIndex = toolTip.indexOf(SequenceStart, endIndex);
|
||||
endIndex = (startIndex != -1) ? toolTip.indexOf(SequenceEnd, startIndex) : -1;
|
||||
}
|
||||
|
||||
if (prevIndex < toolTip.size())
|
||||
{
|
||||
substrings.push_back(toolTip.mid(prevIndex));
|
||||
}
|
||||
|
||||
return substrings.join("");
|
||||
}
|
||||
|
||||
const std::pair<int, const char*> ShortcutManager::QtKeys[] =
|
||||
{
|
||||
std::make_pair((int)Qt::Key_Space , "Space"),
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <QKeySequence>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
|
@ -39,6 +40,9 @@ namespace CSMPrefs
|
|||
|
||||
void convertFromString(const std::string& data, QKeySequence& sequence, int& modifier) const;
|
||||
|
||||
/// Replaces "{sequence-name}" or "{sequence-name:mod}" with the appropriate text
|
||||
QString processToolTip(const QString& toolTip) const;
|
||||
|
||||
private:
|
||||
|
||||
/// Key Sequence, Modifier (for secondary signal)
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <osg/Geometry>
|
||||
#include <osg/PrimitiveSet>
|
||||
|
||||
#include "../../model/prefs/state.hpp"
|
||||
#include "../../model/prefs/shortcutmanager.hpp"
|
||||
|
||||
#include "mask.hpp"
|
||||
|
||||
CSVRender::CellArrowTag::CellArrowTag (CellArrow *arrow)
|
||||
|
@ -35,14 +38,19 @@ QString CSVRender::CellArrowTag::getToolTip (bool hideBasics) const
|
|||
text +=
|
||||
"<p>"
|
||||
"Modify which cells are shown"
|
||||
"<ul><li>Primary-Edit: Add cell in given direction</li>"
|
||||
"<li>Secondary-Edit: Add cell and remove old cell</li>"
|
||||
"<li>Shift Primary-Edit: Add cells in given direction</li>"
|
||||
"<li>Shift Secondary-Edit: Add cells and remove old cells</li>"
|
||||
"<ul><li>{scene-edit-primary}: Add cell in given direction</li>"
|
||||
"<li>{scene-edit-secondary}: Add cell and remove old cell</li>"
|
||||
"<li>{scene-select-primary}: Add cells in given direction</li>"
|
||||
"<li>{scene-select-secondary}: Add cells and remove old cells</li>"
|
||||
"<li>{scene-load-cam-cell}: Load cell where camera is located</li>"
|
||||
"<li>{scene-load-cam-eastcell}: Load cell to east</li>"
|
||||
"<li>{scene-load-cam-northcell}: Load cell to north</li>"
|
||||
"<li>{scene-load-cam-westcell}: Load cell to west</li>"
|
||||
"<li>{scene-load-cam-southcell}: Load cell to south</li>"
|
||||
"</ul>";
|
||||
}
|
||||
|
||||
return text;
|
||||
return CSMPrefs::State::get().getShortcutManager().processToolTip(text);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -447,9 +447,12 @@ void CSVRender::PagedWorldspaceWidget::addCellToSceneFromCamera (int offsetX, in
|
|||
|
||||
CSMWorld::CellCoordinates cellCoordinates(cellX, cellY);
|
||||
|
||||
if (mCells.find(cellCoordinates) == mCells.end())
|
||||
if (!mSelection.has(cellCoordinates))
|
||||
{
|
||||
addCellToScene(cellCoordinates);
|
||||
mSelection.add(cellCoordinates);
|
||||
|
||||
adjustCells();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,69 +4,11 @@
|
|||
#include <QKeyEvent>
|
||||
|
||||
#include "../../model/prefs/state.hpp"
|
||||
#include "../../model/prefs/shortcutmanager.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("");
|
||||
mProcessedToolTip = CSMPrefs::State::get().getShortcutManager().processToolTip(mToolTip);
|
||||
}
|
||||
|
||||
void CSVWidget::PushButton::setExtendedToolTip()
|
||||
|
|
|
@ -33,7 +33,6 @@ namespace CSVWidget
|
|||
|
||||
private:
|
||||
|
||||
// Uses {, :, and } as escape sequences for looking up shortcut settings
|
||||
void processShortcuts();
|
||||
void setExtendedToolTip();
|
||||
|
||||
|
|
Loading…
Reference in a new issue