| 1 | /* |
|---|
| 2 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 3 | * Copyright (C) 2007 Licq developers |
|---|
| 4 | * |
|---|
| 5 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * Licq is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with Licq; if not, write to the Free Software |
|---|
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #ifndef SKINNABLEBUTTON_H |
|---|
| 21 | #define SKINNABLEBUTTON_H |
|---|
| 22 | |
|---|
| 23 | #include <QPushButton> |
|---|
| 24 | |
|---|
| 25 | namespace LicqQtGui |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | namespace Config |
|---|
| 29 | { |
|---|
| 30 | class ButtonSkin; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * Extended QPushButton which can be skinned by using images instead of text |
|---|
| 35 | */ |
|---|
| 36 | class SkinnableButton : public QPushButton |
|---|
| 37 | { |
|---|
| 38 | Q_OBJECT |
|---|
| 39 | |
|---|
| 40 | public: |
|---|
| 41 | /** |
|---|
| 42 | * Constructor, create a skinnable button and apply a skin |
|---|
| 43 | * |
|---|
| 44 | * @param skin Button skin to apply |
|---|
| 45 | * @param defaultText Text to display if skin doesn't contain a caption |
|---|
| 46 | * @param parent Parent widget |
|---|
| 47 | */ |
|---|
| 48 | SkinnableButton(const Config::ButtonSkin& skin, QString defaultText, QWidget* parent = NULL); |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * Constructor, create a default skinnable button |
|---|
| 52 | * |
|---|
| 53 | * @param defaultText Text to display if skin doesn't contain a caption |
|---|
| 54 | * @param parent Parent widget |
|---|
| 55 | */ |
|---|
| 56 | SkinnableButton(QString defaultText, QWidget* parent = 0); |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * Apply a skin |
|---|
| 60 | * |
|---|
| 61 | * @param skin New skin to use |
|---|
| 62 | */ |
|---|
| 63 | void applySkin(const Config::ButtonSkin& skin); |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * Get the keyboard modifiers active when the button was last pressed |
|---|
| 67 | * |
|---|
| 68 | * @return Mask of active keyboard modifiers |
|---|
| 69 | */ |
|---|
| 70 | Qt::KeyboardModifiers modifiersWhenPressed(); |
|---|
| 71 | |
|---|
| 72 | private: |
|---|
| 73 | /** |
|---|
| 74 | * Mouse button pressed |
|---|
| 75 | * |
|---|
| 76 | * @param e Event object |
|---|
| 77 | */ |
|---|
| 78 | virtual void mousePressEvent(QMouseEvent* e); |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * Cursor has entered button |
|---|
| 82 | * |
|---|
| 83 | * @param e Event object |
|---|
| 84 | */ |
|---|
| 85 | virtual void enterEvent(QEvent* e); |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | * Cursor has left button |
|---|
| 89 | * |
|---|
| 90 | * @param e Event object |
|---|
| 91 | */ |
|---|
| 92 | virtual void leaveEvent(QEvent* e); |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Draw button |
|---|
| 96 | * |
|---|
| 97 | * @param e Event object |
|---|
| 98 | */ |
|---|
| 99 | virtual void paintEvent(QPaintEvent* e); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | QString myDefaultText; |
|---|
| 103 | Qt::KeyboardModifiers myPressedModifiers; |
|---|
| 104 | QPixmap myNormalImage, myHighlightedImage, myPressedImage; |
|---|
| 105 | }; |
|---|
| 106 | |
|---|
| 107 | } // namespace LicqQtGui |
|---|
| 108 | |
|---|
| 109 | #endif |
|---|