mirror of
https://github.com/libretro/gambatte-libretro.git
synced 2025-02-11 11:25:16 +00:00
Prevent all text editing of input boxes.
Add custom context menu to input boxes. git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@162 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24
This commit is contained in:
parent
a0bc227484
commit
0da282ee15
@ -1,5 +1,5 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aamås *
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
@ -18,7 +18,8 @@
|
||||
***************************************************************************/
|
||||
#include "inputdialog.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
@ -384,28 +385,23 @@ int pollJsEvent(SDL_Event *ev) {
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
class InputBox : public QLineEdit {
|
||||
QWidget *nextFocus;
|
||||
SDL_Event data;
|
||||
int timerId;
|
||||
|
||||
protected:
|
||||
void focusInEvent(QFocusEvent *event);
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void timerEvent(QTimerEvent */*event*/);
|
||||
|
||||
public:
|
||||
InputBox(QWidget *nextFocus = 0);
|
||||
void setData(const SDL_Event &data) { setData(data.id, data.value); }
|
||||
void setData(unsigned id, int value = InputDialog::KBD_VALUE);
|
||||
void setNextFocus(QWidget *const nextFocus) { this->nextFocus = nextFocus; }
|
||||
const SDL_Event& getData() const { return data; }
|
||||
};
|
||||
|
||||
InputBox::InputBox(QWidget *nextFocus) : nextFocus(nextFocus), timerId(0) {
|
||||
// setReadOnly(true);
|
||||
setData(0, InputDialog::NULL_VALUE);
|
||||
connect(this, SIGNAL(textEdited(const QString&)), this, SLOT(textEditedSlot(const QString&)));
|
||||
}
|
||||
|
||||
void InputBox::contextMenuEvent(QContextMenuEvent *event) {
|
||||
QMenu *const menu = new QMenu(this);
|
||||
|
||||
menu->addAction(tr("&Copy"), this, SLOT(copy()))->setEnabled(hasSelectedText());
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr("&Select All"), this, SLOT(selectAll()))->setEnabled(!displayText().isEmpty());
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr("C&lear"), this, SLOT(clearData()))->setEnabled(getData().value != InputDialog::NULL_VALUE);
|
||||
menu->exec(event->globalPos());
|
||||
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void InputBox::focusInEvent(QFocusEvent *event) {
|
||||
@ -515,9 +511,9 @@ void InputBox::setData(const unsigned id, const int value) {
|
||||
|
||||
void InputBoxPair::clear() {
|
||||
if (altBox->getData().value != InputDialog::NULL_VALUE)
|
||||
altBox->setData(0, InputDialog::NULL_VALUE);
|
||||
altBox->clearData();
|
||||
else
|
||||
mainBox->setData(0, InputDialog::NULL_VALUE);
|
||||
mainBox->clearData();
|
||||
}
|
||||
|
||||
InputDialog::InputDialog(const std::vector<MediaSource::ButtonInfo> &buttonInfos,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aamås *
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
@ -20,6 +20,7 @@
|
||||
#define INPUTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
#include <vector>
|
||||
#include "SDL_Joystick/include/SDL_event.h"
|
||||
#include "mediasource.h"
|
||||
@ -30,20 +31,7 @@ enum { AXIS_CENTERED = 0, AXIS_POSITIVE = 1, AXIS_NEGATIVE = 2 };
|
||||
// only hats can have multiple bits set at once. In practice only axis values are converted (to AXIS_CENTERED, AXIS_POSITIVE or AXIS_NEGATIVE).
|
||||
int pollJsEvent(SDL_Event *ev);
|
||||
|
||||
class InputBox;
|
||||
|
||||
class InputBoxPair : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InputBox *const mainBox;
|
||||
InputBox *const altBox;
|
||||
|
||||
InputBoxPair(InputBox *mainBox, InputBox *altBox) : mainBox(mainBox), altBox(altBox) {}
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
};
|
||||
class InputBoxPair;
|
||||
|
||||
class InputDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
@ -69,4 +57,47 @@ public slots:
|
||||
void reject();
|
||||
};
|
||||
|
||||
class InputBox : public QLineEdit {
|
||||
Q_OBJECT
|
||||
|
||||
QWidget *nextFocus;
|
||||
SDL_Event data;
|
||||
int timerId;
|
||||
|
||||
private slots:
|
||||
void textEditedSlot(const QString &) {
|
||||
setData(data);
|
||||
}
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void focusInEvent(QFocusEvent *event);
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void timerEvent(QTimerEvent */*event*/);
|
||||
|
||||
public:
|
||||
InputBox(QWidget *nextFocus = 0);
|
||||
void setData(const SDL_Event &data) { setData(data.id, data.value); }
|
||||
void setData(unsigned id, int value = InputDialog::KBD_VALUE);
|
||||
void setNextFocus(QWidget *const nextFocus) { this->nextFocus = nextFocus; }
|
||||
const SDL_Event& getData() const { return data; }
|
||||
|
||||
public slots:
|
||||
void clearData() { setData(0, InputDialog::NULL_VALUE); }
|
||||
};
|
||||
|
||||
class InputBoxPair : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InputBox *const mainBox;
|
||||
InputBox *const altBox;
|
||||
|
||||
InputBoxPair(InputBox *mainBox, InputBox *altBox) : mainBox(mainBox), altBox(altBox) {}
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user