diff --git a/apps/opencs/model/prefs/shortcutmanager.cpp b/apps/opencs/model/prefs/shortcutmanager.cpp index e259398b5..37eec0415 100644 --- a/apps/opencs/model/prefs/shortcutmanager.cpp +++ b/apps/opencs/model/prefs/shortcutmanager.cpp @@ -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 ShortcutManager::QtKeys[] = { std::make_pair((int)Qt::Key_Space , "Space"), diff --git a/apps/opencs/model/prefs/shortcutmanager.hpp b/apps/opencs/model/prefs/shortcutmanager.hpp index 26bdc4255..bb081a82a 100644 --- a/apps/opencs/model/prefs/shortcutmanager.hpp +++ b/apps/opencs/model/prefs/shortcutmanager.hpp @@ -5,6 +5,7 @@ #include #include +#include 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) diff --git a/apps/opencs/view/render/cellarrow.cpp b/apps/opencs/view/render/cellarrow.cpp index 6d8fa1c6c..b8c89c83d 100644 --- a/apps/opencs/view/render/cellarrow.cpp +++ b/apps/opencs/view/render/cellarrow.cpp @@ -7,6 +7,9 @@ #include #include +#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 += "

" "Modify which cells are shown" - "

  • Primary-Edit: Add cell in given direction
  • " - "
  • Secondary-Edit: Add cell and remove old cell
  • " - "
  • Shift Primary-Edit: Add cells in given direction
  • " - "
  • Shift Secondary-Edit: Add cells and remove old cells
  • " + "
    • {scene-edit-primary}: Add cell in given direction
    • " + "
    • {scene-edit-secondary}: Add cell and remove old cell
    • " + "
    • {scene-select-primary}: Add cells in given direction
    • " + "
    • {scene-select-secondary}: Add cells and remove old cells
    • " + "
    • {scene-load-cam-cell}: Load cell where camera is located
    • " + "
    • {scene-load-cam-eastcell}: Load cell to east
    • " + "
    • {scene-load-cam-northcell}: Load cell to north
    • " + "
    • {scene-load-cam-westcell}: Load cell to west
    • " + "
    • {scene-load-cam-southcell}: Load cell to south
    • " "
    "; } - return text; + return CSMPrefs::State::get().getShortcutManager().processToolTip(text); } diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 786beb530..ab2e252af 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -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(); } } diff --git a/apps/opencs/view/widget/pushbutton.cpp b/apps/opencs/view/widget/pushbutton.cpp index 100f3bd43..c4e6a4144 100644 --- a/apps/opencs/view/widget/pushbutton.cpp +++ b/apps/opencs/view/widget/pushbutton.cpp @@ -4,69 +4,11 @@ #include #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() diff --git a/apps/opencs/view/widget/pushbutton.hpp b/apps/opencs/view/widget/pushbutton.hpp index 65df1b7e3..bdbdc9c4d 100644 --- a/apps/opencs/view/widget/pushbutton.hpp +++ b/apps/opencs/view/widget/pushbutton.hpp @@ -33,7 +33,6 @@ namespace CSVWidget private: - // Uses {, :, and } as escape sequences for looking up shortcut settings void processShortcuts(); void setExtendedToolTip();