Angus Leeming wrote:
> to generate the QString. Something like this, perhaps:

Actually, reading the Qt docs, this is the way to do it:

#include <qkeysequence.h>
#include <qstring.h>
#include <qtextcodec.h>
#include <iostream>
#include <string>

QString const toqstr(char const * str)
{
        QTextCodec * codec = QTextCodec::codecForLocale();
        return codec->toUnicode(str);
}


QString const toqstr(std::string const & str)
{
        return toqstr(str.c_str());
}


int main()
{
        std::string const binding = "Ctrl+o";

        QKeySequence const kseq(toqstr(binding));
        QString const qbinding = static_cast<QString>(kseq);

        QKeySequence const kseq2(Qt::Key_O + Qt::CTRL);
        QString const qbinding2 = static_cast<QString>(kseq2);

        std::cout << "Binding is \"" << binding << "\"\n"
                  << "kseq is \"" << kseq << "\"\n"
                  << "qbinding is \"" << qbinding << "\"\n"
                  << "kseq2 is \"" << kseq2 << "\"\n"
                  << "qbinding2 is \"" << qbinding2 << '"' 
                  << std::endl;
        return 0;
}

Compiled with:
        $ g++ -I/usr/lib/qt-3.1/include -o trial trial.C \
          -L/usr/lib/qt-3.1/lib -lqt-mt
To give
        $ ./trial
        Binding is "Ctrl+o"
        kseq is "272629839"
        qbinding is "Ctrl+O"
        kseq2 is "4194383"
        qbinding2 is "Ctrl+O"

I guess that the effort for you lies in turning the lyx-style "C-o"
into the QKeySequence(Qt::Key_O + Qt::CTRL). Thereafter generation of
the Qt-style "Ctrl+O" is pretty automatic. 

That said, I see that the necessary magic (key_modifier::state and
string_to_qkey) exists already, so this should also be
straightforward.

-- 
Angus

Reply via email to