| 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 SKINNABLELABEL_H |
|---|
| 21 | #define SKINNABLELABEL_H |
|---|
| 22 | |
|---|
| 23 | #include <QLabel> |
|---|
| 24 | #include <QList> |
|---|
| 25 | |
|---|
| 26 | class QMenu; |
|---|
| 27 | |
|---|
| 28 | namespace LicqQtGui |
|---|
| 29 | { |
|---|
| 30 | |
|---|
| 31 | namespace Config |
|---|
| 32 | { |
|---|
| 33 | class LabelSkin; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * Extended QLabel which can be skinned, show images and have a popup menu |
|---|
| 38 | */ |
|---|
| 39 | class SkinnableLabel : public QLabel |
|---|
| 40 | { |
|---|
| 41 | Q_OBJECT |
|---|
| 42 | |
|---|
| 43 | public: |
|---|
| 44 | /** |
|---|
| 45 | * Constructor, create a skinnable label and apply a skin |
|---|
| 46 | * |
|---|
| 47 | * @param skin Label skin to apply |
|---|
| 48 | * @param menu Popup menu to show when right clicking on label |
|---|
| 49 | * @param parent Parent widget |
|---|
| 50 | */ |
|---|
| 51 | SkinnableLabel(const Config::LabelSkin& skin, QMenu* menu = NULL, QWidget* parent = NULL); |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Constructor, create a default skinnable label |
|---|
| 55 | * |
|---|
| 56 | * @param menu Popup menu to show when right clicking on label |
|---|
| 57 | * @param parent Parent widget |
|---|
| 58 | */ |
|---|
| 59 | SkinnableLabel(QMenu* menu = NULL, QWidget* parent = NULL); |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Apply a skin |
|---|
| 63 | * |
|---|
| 64 | * @param skin New skin to use |
|---|
| 65 | */ |
|---|
| 66 | void applySkin(const Config::LabelSkin& skin); |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | * Convenience function to set text boldness |
|---|
| 70 | * |
|---|
| 71 | * @param enable True to make text bold, false for normal text |
|---|
| 72 | */ |
|---|
| 73 | void setBold(bool enable); |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * Convenience function to set text italicness |
|---|
| 77 | * |
|---|
| 78 | * @param enable True to make text italic, false for normal text |
|---|
| 79 | */ |
|---|
| 80 | void setItalic(bool enable); |
|---|
| 81 | |
|---|
| 82 | /** |
|---|
| 83 | * Specify an image to display in front of the label text |
|---|
| 84 | * |
|---|
| 85 | * @param p Image |
|---|
| 86 | */ |
|---|
| 87 | void setPrependPixmap(const QPixmap& p); |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * Remove image in front of text |
|---|
| 91 | */ |
|---|
| 92 | void clearPrependPixmap(); |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Add an image to list of images to show |
|---|
| 96 | * |
|---|
| 97 | * @param p Image to add last |
|---|
| 98 | */ |
|---|
| 99 | void addPixmap(const QPixmap& p); |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * Clear list of images to show |
|---|
| 103 | */ |
|---|
| 104 | void clearPixmaps(); |
|---|
| 105 | |
|---|
| 106 | signals: |
|---|
| 107 | /** |
|---|
| 108 | * User double clicked or middle clicked on label |
|---|
| 109 | */ |
|---|
| 110 | void doubleClicked(); |
|---|
| 111 | |
|---|
| 112 | private: |
|---|
| 113 | /** |
|---|
| 114 | * User double clicked on widget |
|---|
| 115 | * |
|---|
| 116 | * @param e Event object |
|---|
| 117 | */ |
|---|
| 118 | virtual void mouseDoubleClickEvent(QMouseEvent* e); |
|---|
| 119 | |
|---|
| 120 | /** |
|---|
| 121 | * User clicked on widget |
|---|
| 122 | * |
|---|
| 123 | * @param e Event object |
|---|
| 124 | */ |
|---|
| 125 | virtual void mousePressEvent(QMouseEvent* e); |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * Draw label |
|---|
| 129 | * |
|---|
| 130 | * @param e Event object |
|---|
| 131 | */ |
|---|
| 132 | virtual void paintEvent(QPaintEvent* e); |
|---|
| 133 | |
|---|
| 134 | QMenu* myPopupMenu; |
|---|
| 135 | QPixmap myBackgroundImage; |
|---|
| 136 | QPixmap myAddPix; |
|---|
| 137 | QList<QPixmap> myPixmaps; |
|---|
| 138 | int myAddIndent, myStartingIndent; |
|---|
| 139 | }; |
|---|
| 140 | |
|---|
| 141 | } // namespace LicqQtGui |
|---|
| 142 | |
|---|
| 143 | #endif |
|---|