2007-10-25 03:08:22 +00:00
|
|
|
/**
|
2013-12-21 11:58:23 +00:00
|
|
|
* \file CustomizedWidgets.cpp
|
2007-10-25 03:08:22 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Bo Peng
|
|
|
|
* \author Edwin Leuven
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2007-10-25 03:08:22 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-07-21 14:54:07 +00:00
|
|
|
The code for the ShortcutWidget class was adapted from
|
2007-10-25 03:08:22 +00:00
|
|
|
kkeysequencewidget.cpp, which is part of the KDE libraries.
|
|
|
|
Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
|
|
|
|
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
|
|
|
|
Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
|
|
|
|
Licensed under version 2 of the General Public License and
|
|
|
|
used here in accordance with the terms of that license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "CustomizedWidgets.h"
|
2007-10-26 23:49:16 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-10-25 03:08:22 +00:00
|
|
|
#include "GuiKeySymbol.h"
|
|
|
|
|
2007-10-26 20:43:22 +00:00
|
|
|
#include <QApplication>
|
2008-02-18 09:44:02 +00:00
|
|
|
#include <QKeyEvent>
|
2008-07-21 14:54:07 +00:00
|
|
|
#include <QMouseEvent>
|
2008-02-18 09:55:14 +00:00
|
|
|
#include <QShowEvent>
|
2007-10-26 20:43:22 +00:00
|
|
|
|
2007-10-25 03:08:22 +00:00
|
|
|
#include "support/qstring_helpers.h"
|
|
|
|
|
|
|
|
|
|
|
|
using lyx::KeySymbol;
|
2007-10-26 20:43:22 +00:00
|
|
|
using lyx::KeySequence;
|
|
|
|
using lyx::KeyModifier;
|
2007-10-25 03:08:22 +00:00
|
|
|
using lyx::toqstr;
|
|
|
|
|
2007-10-29 08:56:30 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2008-07-21 14:54:07 +00:00
|
|
|
ShortcutWidget::ShortcutWidget(QWidget * parent)
|
|
|
|
: QLabel(parent), keysequence_()
|
2007-10-26 20:43:22 +00:00
|
|
|
{
|
|
|
|
has_cursor_ = false;
|
2008-07-22 09:49:38 +00:00
|
|
|
setFrameShape(QFrame::Panel);
|
2008-07-21 14:54:07 +00:00
|
|
|
setFrameShadow(QFrame::Raised);
|
2008-07-22 09:49:38 +00:00
|
|
|
setLineWidth(3);
|
2008-07-21 14:54:07 +00:00
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
|
|
|
setAlignment(Qt::AlignCenter);
|
2007-10-26 20:43:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-21 14:54:07 +00:00
|
|
|
void ShortcutWidget::reset()
|
2007-10-26 20:43:22 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
keysequence_ = KeySequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-21 14:54:07 +00:00
|
|
|
KeySequence const ShortcutWidget::getKeySequence() const
|
2007-10-26 20:43:22 +00:00
|
|
|
{
|
|
|
|
return keysequence_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-12 17:22:51 +00:00
|
|
|
void ShortcutWidget::setKeySequence(lyx::KeySequence const & s)
|
2008-07-22 08:29:50 +00:00
|
|
|
{
|
|
|
|
keysequence_ = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-21 14:54:07 +00:00
|
|
|
void ShortcutWidget::keyPressEvent(QKeyEvent * e)
|
2007-10-25 03:08:22 +00:00
|
|
|
{
|
2007-10-26 20:43:22 +00:00
|
|
|
int const keyQt = e->key();
|
|
|
|
if (!keyQt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(keyQt) {
|
2007-10-25 03:08:22 +00:00
|
|
|
case Qt::Key_AltGr: //or else we get unicode salad
|
|
|
|
case Qt::Key_Shift:
|
|
|
|
case Qt::Key_Control:
|
|
|
|
case Qt::Key_Alt:
|
|
|
|
case Qt::Key_Meta:
|
|
|
|
break;
|
|
|
|
default:
|
2007-10-26 20:43:22 +00:00
|
|
|
appendToSequence(e);
|
2007-10-31 17:15:10 +00:00
|
|
|
setText(toqstr(keysequence_.print(KeySequence::ForGui)));
|
2007-10-25 03:08:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-21 14:54:07 +00:00
|
|
|
bool ShortcutWidget::event(QEvent * e)
|
2007-10-25 03:08:22 +00:00
|
|
|
{
|
2007-10-26 20:43:22 +00:00
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::FocusOut:
|
|
|
|
has_cursor_ = false;
|
2008-07-21 14:54:07 +00:00
|
|
|
setFrameShadow(QFrame::Raised);
|
2007-10-26 20:43:22 +00:00
|
|
|
break;
|
|
|
|
case QEvent::FocusIn:
|
|
|
|
has_cursor_ = true;
|
2008-07-21 14:54:07 +00:00
|
|
|
setFrameShadow(QFrame::Sunken);
|
2007-10-26 20:43:22 +00:00
|
|
|
break;
|
|
|
|
case QEvent::ShortcutOverride:
|
2016-05-17 17:45:37 +00:00
|
|
|
// accepting the ShortcutOverride event lets us override shortcuts
|
|
|
|
// and capture them as keypress events instead
|
|
|
|
e->accept();
|
|
|
|
return true;
|
|
|
|
case QEvent::KeyPress:
|
2007-10-26 20:43:22 +00:00
|
|
|
keyPressEvent(static_cast<QKeyEvent *>(e));
|
|
|
|
return true;
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
case QEvent::Shortcut:
|
|
|
|
return true;
|
2016-05-17 17:45:37 +00:00
|
|
|
default:
|
2007-10-26 20:43:22 +00:00
|
|
|
break;
|
2007-10-25 03:08:22 +00:00
|
|
|
}
|
2008-07-21 14:54:07 +00:00
|
|
|
return QLabel::event(e);
|
2007-10-25 03:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-21 14:54:07 +00:00
|
|
|
void ShortcutWidget::appendToSequence(QKeyEvent * e)
|
2007-10-26 20:43:22 +00:00
|
|
|
{
|
|
|
|
KeySymbol sym;
|
|
|
|
setKeySymbol(&sym, e);
|
2016-05-17 17:45:37 +00:00
|
|
|
|
2009-07-06 16:14:20 +00:00
|
|
|
if (sym.isOK()) {
|
|
|
|
KeyModifier mod = lyx::q_key_state(e->modifiers());
|
|
|
|
keysequence_.addkey(sym, mod, lyx::NoModifier);
|
|
|
|
}
|
2007-10-26 20:43:22 +00:00
|
|
|
}
|
|
|
|
|
2008-07-22 08:29:50 +00:00
|
|
|
|
|
|
|
void ShortcutWidget::removeFromSequence()
|
|
|
|
{
|
|
|
|
keysequence_.removeKey();
|
|
|
|
setText(toqstr(keysequence_.print(KeySequence::ForGui)));
|
|
|
|
}
|
|
|
|
|
2007-10-29 08:56:30 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-10-25 03:08:22 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_CustomizedWidgets.cpp"
|