| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2000-2006 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "emoticonlabel.h" |
|---|
| 22 | |
|---|
| 23 | #include <QKeyEvent> |
|---|
| 24 | #include <QMouseEvent> |
|---|
| 25 | |
|---|
| 26 | using namespace LicqQtGui; |
|---|
| 27 | |
|---|
| 28 | EmoticonLabel::EmoticonLabel(const QString& file, const QString& value, QWidget* parent) |
|---|
| 29 | : QPushButton(parent), |
|---|
| 30 | myValue(value) |
|---|
| 31 | { |
|---|
| 32 | QPixmap icon = QPixmap(file); |
|---|
| 33 | setIconSize(icon.size()); |
|---|
| 34 | setIcon(icon); |
|---|
| 35 | setToolTip(value); |
|---|
| 36 | setFixedSize(icon.size() + QSize(10, 10)); |
|---|
| 37 | setFlat(true); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | void EmoticonLabel::mouseReleaseEvent(QMouseEvent* /* e */) |
|---|
| 41 | { |
|---|
| 42 | if (underMouse()) |
|---|
| 43 | emit clicked(myValue); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | void EmoticonLabel::keyPressEvent(QKeyEvent* e) |
|---|
| 47 | { |
|---|
| 48 | if (e->modifiers() != Qt::NoModifier) |
|---|
| 49 | return; |
|---|
| 50 | |
|---|
| 51 | switch (e->key()) |
|---|
| 52 | { |
|---|
| 53 | case Qt::Key_Return: // Fall through |
|---|
| 54 | case Qt::Key_Enter: |
|---|
| 55 | case Qt::Key_Space: |
|---|
| 56 | emit clicked(myValue); |
|---|
| 57 | break; |
|---|
| 58 | |
|---|
| 59 | case Qt::Key_Up: // Fall through |
|---|
| 60 | case Qt::Key_Down: |
|---|
| 61 | emit move(this, e->key()); |
|---|
| 62 | break; |
|---|
| 63 | |
|---|
| 64 | default: |
|---|
| 65 | QPushButton::keyPressEvent(e); |
|---|
| 66 | break; |
|---|
| 67 | } |
|---|
| 68 | } |
|---|