New misc_helpers files to group some utility classes

Currently, it contains only the KeyEventFilter class, and a new
ClickableLabel class (not used yet).
This commit is contained in:
Olivier Teulière 2012-03-18 00:37:57 +01:00
parent 96c0497f7b
commit 35acc7b7a3
5 changed files with 133 additions and 47 deletions

View file

@ -63,6 +63,7 @@ eliot_SOURCES = \
timer_widget.cpp timer_widget.h \
tile_layout.cpp tile_layout.h \
validator_factory.h validator_factory.cpp \
misc_helpers.cpp misc_helpers.h \
custom_popup.cpp custom_popup.h \
arbitration_widget.cpp arbitration_widget.h \
bag_widget.cpp bag_widget.h \
@ -100,6 +101,7 @@ nodist_eliot_SOURCES = \
timer_widget.moc.cpp \
tile_layout.moc.cpp \
validator_factory.moc.cpp \
misc_helpers.moc.cpp \
custom_popup.moc.cpp \
players_table_helper.moc.cpp \
new_game.moc.cpp \

View file

@ -34,6 +34,7 @@
#include "validator_factory.h"
#include "play_word_mediator.h"
#include "custom_popup.h"
#include "misc_helpers.h"
#include "public_game.h"
#include "player.h"
@ -981,29 +982,3 @@ void ArbitrationWidget::endTurn()
emit gameUpdated();
}
KeyEventFilter::KeyEventFilter(QObject *parent, int key, int modifiers)
: QObject(parent), m_modifiers(modifiers), m_key(key)
{
}
bool KeyEventFilter::eventFilter(QObject *obj, QEvent *event)
{
// If the Delete key is pressed, remove the selected line, if any
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == m_key &&
keyEvent->modifiers() == m_modifiers)
{
emit keyPressed();
return true;
}
}
// Standard event processing
return QObject::eventFilter(obj, event);
}

View file

@ -141,26 +141,5 @@ private:
QString formatMove(const Move &iMove) const;
};
/// Event filter used for the edition of the players display
class KeyEventFilter: public QObject
{
Q_OBJECT;
public:
KeyEventFilter(QObject *parent, int key, int modifier = Qt::NoModifier);
signals:
/// As its name indicates...
void keyPressed();
protected:
virtual bool eventFilter(QObject *obj, QEvent *event);
private:
int m_modifiers;
int m_key;
};
#endif

63
qt/misc_helpers.cpp Normal file
View file

@ -0,0 +1,63 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2012 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <QtGui/QKeyEvent>
#include "misc_helpers.h"
KeyEventFilter::KeyEventFilter(QObject *parent, int key, int modifiers)
: QObject(parent), m_modifiers(modifiers), m_key(key)
{
}
bool KeyEventFilter::eventFilter(QObject *obj, QEvent *event)
{
// If the Delete key is pressed, remove the selected line, if any
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == m_key &&
keyEvent->modifiers() == m_modifiers)
{
emit keyPressed();
return true;
}
}
// Standard event processing
return QObject::eventFilter(obj, event);
}
ClickableLabel::ClickableLabel(QWidget *parent)
: QLabel(parent)
{
}
void ClickableLabel::mousePressEvent(QMouseEvent *event)
{
QLabel::mousePressEvent(event);
emit clicked();
}

67
qt/misc_helpers.h Normal file
View file

@ -0,0 +1,67 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2012 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#ifndef MISC_HELPERS_H_
#define MISC_HELPERS_H_
#include <QtGui/QLabel>
class QMouseEvent;
class QEvent;
/// Event filter used for the edition of the players display
class KeyEventFilter: public QObject
{
Q_OBJECT;
public:
KeyEventFilter(QObject *parent, int key, int modifier = Qt::NoModifier);
signals:
/// As its name indicates...
void keyPressed();
protected:
virtual bool eventFilter(QObject *obj, QEvent *event);
private:
int m_modifiers;
int m_key;
};
class ClickableLabel: public QLabel
{
Q_OBJECT;
public:
explicit ClickableLabel(QWidget *parent = 0);
signals:
void clicked();
protected:
virtual void mousePressEvent(QMouseEvent *event);
};
#endif