1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007-2009 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   /**
113    * Mouse wheel was scrolled up on this label
114    */
115   void wheelUp();
116 
117   /**
118    * Mouse wheel was scrolled down on this label
119    */
120   void wheelDown();
121 
122 private:
123   /**
124    * User double clicked on widget
125    *
126    * @param e Event object
127    */
128   virtual void mouseDoubleClickEvent(QMouseEvent* e);
129 
130   /**
131    * User clicked on widget
132    *
133    * @param e Event object
134    */
135   virtual void mousePressEvent(QMouseEvent* e);
136 
137   /**
138    * Draw label
139    *
140    * @param e Event object
141    */
142   virtual void paintEvent(QPaintEvent* e);
143 
144   /**
145    * Wheel event, overloaded to emit wheelUp and wheelDown signals
146    *
147    * @param event Event object
148    */
149   void wheelEvent(QWheelEvent* event);
150 
151   QMenu* myPopupMenu;
152   QPixmap myBackgroundImage;
153   QPixmap myAddPix;
154   QList<QPixmap> myPixmaps;
155   int myAddIndent, myStartingIndent;
156 };
157 
158 } // namespace LicqQtGui
159 
160 #endif
161