1 /***************************************************************************
2 * Copyright (C) 2003 by S�astien Laot *
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. *
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. *
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 ***************************************************************************/
26 #include <Q3BoxLayout>
48 /** Store the style of links
49 * @author S�astien Laot
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;
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
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);
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
);
122 void initLabel(int hAlign
, int vAlign
);
123 void enterEvent(QEvent
*);
124 void leaveEvent(QEvent
*);
126 Q3BoxLayout
*m_layout
;
129 QSpacerItem
*m_spacer1
;
130 QSpacerItem
*m_spacer2
;
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
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.
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
= "");
181 /** A widget to edit a LinkLook, showing a live example to the user.
182 * @author S�astien Laot
184 class LinkLookEditWidget
: public QWidget
188 LinkLookEditWidget(KCModule
* module
, const QString exTitle
, const QString exIcon
,
189 QWidget
*parent
= 0, const char *name
= 0, WFlags fl
= 0);
190 ~LinkLookEditWidget();
192 void saveToLook(LinkLook
*look
);
193 void set(LinkLook
*look
);
195 void slotChangeLook();
200 QComboBox
*m_underlining
;
201 KColorCombo2
*m_color
;
202 KColorCombo2
*m_hoverColor
;
203 IconSizeCombo
*m_iconSize
;
204 QComboBox
*m_preview
;
206 LinkLabel
*m_example
;
213 #endif // LINKLABEL_H