Ran qt3to4
[basket4.git] / src / linklabel.h
blob8084534b7a84750d5ef1af7aea395d1c33ac10e9
1 /***************************************************************************
2 * Copyright (C) 2003 by S�astien Laot *
3 * slaout@linux62.org *
4 * *
5 * This program 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 * This program 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 this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef LINKLABEL_H
22 #define LINKLABEL_H
24 #include <q3frame.h>
25 //Added by qt3to4:
26 #include <Q3BoxLayout>
27 #include <QPixmap>
28 #include <QLabel>
29 #include <QEvent>
31 class QString;
32 class KURL;
33 class QColor;
34 class QLabel;
35 class Q3BoxLayout;
36 class QSpacerItem;
37 class QPushButton;
38 class QCheckBox;
39 class QComboBox;
41 class KColorCombo2;
42 class IconSizeCombo;
44 class HTMLExporter;
45 class HelpLabel;
46 class KCModule;
48 /** Store the style of links
49 * @author S�astien Laot
51 class LinkLook
53 public:
54 enum Underlining { Always = 0, Never, OnMouseHover, OnMouseOutside };
55 enum Preview { None = 0, IconSize, TwiceIconSize, ThreeIconSize };
56 LinkLook(bool useLinkColor = true, bool canPreview = true);
57 LinkLook(const LinkLook &other);
58 void setLook( bool italic, bool bold, int underlining,
59 QColor color, QColor hoverColor,
60 int iconSize, int preview /*= None*/ );
61 inline bool italic() const { return m_italic; }
62 inline bool bold() const { return m_bold; }
63 inline int underlining() const { return m_underlining; }
64 inline QColor color() const { return m_color; }
65 inline QColor hoverColor() const { return m_hoverColor; }
66 inline int iconSize() const { return m_iconSize; }
67 inline int preview() const { return m_preview; }
68 inline bool useLinkColor() const { return m_useLinkColor; }
69 inline bool canPreview() const { return m_canPreview; }
70 /* Helpping Functions */
71 bool underlineOutside() const { return underlining() == Always || underlining() == OnMouseOutside; }
72 bool underlineInside() const { return underlining() == Always || underlining() == OnMouseHover; }
73 bool previewEnabled() const { return canPreview() && preview() > None; }
74 int previewSize() const;
75 QColor effectiveColor() const;
76 QColor effectiveHoverColor() const;
77 QColor defaultColor() const;
78 QColor defaultHoverColor() const;
79 QString toCSS(const QString &cssClass, const QColor &defaultTextColor) const;
80 private:
81 bool m_italic;
82 bool m_bold;
83 int m_underlining;
84 QColor m_color;
85 QColor m_hoverColor;
86 int m_iconSize;
87 int m_preview;
88 bool m_useLinkColor;
89 bool m_canPreview;
90 public:
91 /* Global Looks */
92 static LinkLook *soundLook;
93 static LinkLook *fileLook;
94 static LinkLook *localLinkLook;
95 static LinkLook *networkLinkLook;
96 static LinkLook *launcherLook;
97 /* Static method to get a LinkLook from an URL */
98 static LinkLook* lookForURL(const KURL &url);
101 /** Used to represent links with icon and specific look
102 * Note : This label will appear blank while LinkLook willn't be set
103 * @author S�astien Laot
105 class LinkLabel : public Q3Frame
107 Q_OBJECT
108 public:
109 LinkLabel(int hAlign, int vAlign, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
110 LinkLabel(const QString &title, const QString &icon, LinkLook *look, int hAlign, int vAlign,
111 QWidget *parent = 0, const char *name = 0, WFlags f = 0);
112 ~LinkLabel();
113 public:
114 void setLink(const QString &title, const QString &icon, LinkLook *look = 0);
115 void setLook(LinkLook *look);
116 void setAlign(int hAlign, int vAlign);
117 void setSelected(bool selected);
118 void setPaletteBackgroundColor(const QColor &color);
119 int heightForWidth(int w = -1) const;
120 QString toHtml(const QString &imageName);
121 protected:
122 void initLabel(int hAlign, int vAlign);
123 void enterEvent(QEvent*);
124 void leaveEvent(QEvent*);
125 private:
126 Q3BoxLayout *m_layout;
127 QLabel *m_icon;
128 QLabel *m_title;
129 QSpacerItem *m_spacer1;
130 QSpacerItem *m_spacer2;
132 bool m_isSelected;
133 bool m_isHovered;
135 LinkLook *m_look;
136 int m_hAlign;
137 int m_vAlign;
140 /** THE NEW CLASS TO DISPLAY Links FOR THE NEW BASKET ENGINE.
141 * We should get ride of class LinkLabel soon.
142 * And LinkLabel will be entirely rewritten to use this LinkDisplay as the drawing primitives.
143 * @author S�astien Laot
145 class LinkDisplay
147 public:
148 LinkDisplay(); /// << Create a new empty unselected LinkDisplay. Please then call setLink() to make sense.
149 // Configure the link displayer:
150 void setLink(const QString &title, const QString &icon, LinkLook *look, const QFont &font); /// << Change the content and disposition. minWidth(), width() & height() can have changed. Keep the old preview (if any)
151 void setLink(const QString &title, const QString &icon, const QPixmap &preview, LinkLook *look, const QFont &font); /// << Idem but change the preview too (or remove it if it is invalid)
152 void setWidth(int width); /// << Set a new width. @see height() that will be computed.
153 // Get its properties:
154 int minWidth() const { return m_minWidth; } /// << @return the minimum width to display this link.
155 int maxWidth() const { return m_maxWidth; } /// << @return the maximum width to display this link.
156 int width() const { return m_width; } /// << @return the width of the link. It is never less than minWidth()!
157 int height() const { return m_height; } /// << @return the height if the link after having set it a width.
158 // And finaly, use it:
159 void paint(QPainter *painter, int x, int y, int width, int height, const QColorGroup &colorGroup, bool isDefaultColor, bool isSelected, bool isHovered, bool isIconButtonHovered) const; /// << Draw the link on a painter. Set textColor to be !isValid() to use the LinkLook color. Otherwise it will use this color!
160 QPixmap feedbackPixmap(int width, int height, const QColorGroup &colorGroup, bool isDefaultColor); /// << @return the pixmap to put under the cursor while dragging this object.
161 // Eventually get some information about the link display:
162 bool iconButtonAt(const QPoint &pos) const; /// << @return true if the icon button is under point @p pos.
163 QRect iconButtonRect() const; /// << @return the rectangle of the icon button.
164 // Utility function:
165 QFont labelFont(QFont font, bool isIconButtonHovered) const; /// << @return the font for this link, according to parent font AND LinkLook!
166 int heightForWidth(int width) const; /// << @return the needed height to display the link in function of a width.
167 QString toHtml(const QString &imageName) const; /// << Convert the link to HTML code, using the LinkLook to style it.
168 QString toHtml(HTMLExporter *exporter, const KURL &url, const QString &title = "");
169 private:
170 QString m_title;
171 QString m_icon;
172 QPixmap m_preview;
173 LinkLook *m_look;
174 QFont m_font;
175 int m_minWidth;
176 int m_maxWidth;
177 int m_width;
178 int m_height;
181 /** A widget to edit a LinkLook, showing a live example to the user.
182 * @author S�astien Laot
184 class LinkLookEditWidget : public QWidget
186 Q_OBJECT
187 public:
188 LinkLookEditWidget(KCModule* module, const QString exTitle, const QString exIcon,
189 QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
190 ~LinkLookEditWidget();
191 void saveChanges();
192 void saveToLook(LinkLook *look);
193 void set(LinkLook *look);
194 private slots:
195 void slotChangeLook();
196 protected:
197 LinkLook *m_look;
198 QCheckBox *m_italic;
199 QCheckBox *m_bold;
200 QComboBox *m_underlining;
201 KColorCombo2 *m_color;
202 KColorCombo2 *m_hoverColor;
203 IconSizeCombo *m_iconSize;
204 QComboBox *m_preview;
205 LinkLook *m_exLook;
206 LinkLabel *m_example;
207 QString m_exTitle;
208 QString m_exIcon;
209 HelpLabel *m_hLabel;
210 QLabel *m_label;
213 #endif // LINKLABEL_H