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 ***************************************************************************/
23 #include <Q3HBoxLayout>
24 #include <Q3GridLayout>
28 #include <Q3VBoxLayout>
29 #include <Q3BoxLayout>
32 #include <kiconloader.h>
35 #include <qpushbutton.h>
36 #include <qcheckbox.h>
37 #include <qcombobox.h>
38 #include <q3hgroupbox.h>
40 #include <kglobalsettings.h>
42 #include <kapplication.h>
43 #include <kaboutdata.h>
44 #include <kdialogbase.h>
48 #include "linklabel.h"
49 #include "variouswidgets.h"
52 #include "kcolorcombo2.h"
53 #include "htmlexporter.h"
57 LinkLook
*LinkLook::soundLook
= new LinkLook(/*useLinkColor=*/false, /*canPreview=*/false);
58 LinkLook
*LinkLook::fileLook
= new LinkLook(/*useLinkColor=*/false, /*canPreview=*/true);
59 LinkLook
*LinkLook::localLinkLook
= new LinkLook(/*useLinkColor=*/true, /*canPreview=*/true);
60 LinkLook
*LinkLook::networkLinkLook
= new LinkLook(/*useLinkColor=*/true, /*canPreview=*/false);
61 LinkLook
*LinkLook::launcherLook
= new LinkLook(/*useLinkColor=*/true, /*canPreview=*/false);
63 LinkLook::LinkLook(bool useLinkColor
, bool canPreview
)
65 m_useLinkColor
= useLinkColor
;
66 m_canPreview
= canPreview
;
70 LinkLook::LinkLook(const LinkLook
&other
)
72 m_useLinkColor
= other
.useLinkColor();
73 m_canPreview
= other
.canPreview();
74 setLook( other
.italic(), other
.bold(), other
.underlining(),
75 other
.color(), other
.hoverColor(),
76 other
.iconSize(), other
.preview() );
79 void LinkLook::setLook(bool italic
, bool bold
, int underlining
,
80 QColor color
, QColor hoverColor
,
81 int iconSize
, int preview
)
85 m_underlining
= underlining
;
87 m_hoverColor
= hoverColor
;
88 m_iconSize
= iconSize
;
89 m_preview
= (canPreview() ? preview
: None
);
92 int LinkLook::previewSize() const
94 if (previewEnabled()) {
98 case IconSize
: return iconSize();
99 case TwiceIconSize
: return iconSize() * 2;
100 case ThreeIconSize
: return iconSize() * 3;
106 QColor
LinkLook::effectiveColor() const
108 if (m_color
.isValid())
111 return defaultColor();
114 QColor
LinkLook::effectiveHoverColor() const
116 if (m_hoverColor
.isValid())
119 return defaultHoverColor();
122 QColor
LinkLook::defaultColor() const
125 return KGlobalSettings::linkColor();
127 return KGlobalSettings::textColor();
130 QColor
LinkLook::defaultHoverColor() const
135 LinkLook
* LinkLook::lookForURL(const KUrl
&url
)
137 return url
.isLocalFile() ? localLinkLook
: networkLinkLook
;
140 QString
LinkLook::toCSS(const QString
&cssClass
, const QColor
&defaultTextColor
) const
142 // Set the link class:
143 QString css
= QString(" .%1 a { display: block; width: 100%;").arg(cssClass
);
144 if (underlineOutside())
145 css
+= " text-decoration: underline;";
147 css
+= " text-decoration: none;";
148 if (m_italic
== true)
149 css
+= " font-style: italic;";
151 css
+= " font-weight: bold;";
152 QColor textColor
= (color().isValid() || m_useLinkColor
? effectiveColor() : defaultTextColor
);
153 css
+= QString(" color: %1; }\n").arg(textColor
.name());
155 // Set the hover state class:
157 if (m_underlining
== OnMouseHover
)
158 hover
= "text-decoration: underline;";
159 else if (m_underlining
== OnMouseOutside
)
160 hover
= "text-decoration: none;";
161 if (effectiveHoverColor() != effectiveColor()) {
162 if (!hover
.isEmpty())
164 hover
+= QString("color: %4;").arg(effectiveHoverColor().name());
167 // But include it only if it contain a different style than non-hover state:
168 if (!hover
.isEmpty())
169 css
+= QString(" .%1 a:hover { %2 }\n").arg(cssClass
, hover
);
176 LinkLabel::LinkLabel(int hAlign
, int vAlign
, QWidget
*parent
, const char *name
, Qt::WFlags f
)
177 : Q3Frame(parent
, name
, f
), m_isSelected(false), m_isHovered(false), m_look(0)
179 initLabel(hAlign
, vAlign
);
182 LinkLabel::LinkLabel(const QString
&title
, const QString
&icon
, LinkLook
*look
, int hAlign
, int vAlign
,
183 QWidget
*parent
, const char *name
, Qt::WFlags f
)
184 : Q3Frame(parent
, name
, f
), m_isSelected(false), m_isHovered(false), m_look(0)
186 initLabel(hAlign
, vAlign
);
187 setLink(title
, icon
, look
);
190 void LinkLabel::initLabel(int hAlign
, int vAlign
)
192 m_layout
= new Q3BoxLayout(this, Q3BoxLayout::LeftToRight
);
193 m_icon
= new QLabel(this);
194 m_title
= new QLabel(this);
195 m_spacer1
= new QSpacerItem(0, 0, QSizePolicy::Preferred
/*Expanding*/, QSizePolicy::Preferred
/*Expanding*/);
196 m_spacer2
= new QSpacerItem(0, 0, QSizePolicy::Preferred
/*Expanding*/, QSizePolicy::Preferred
/*Expanding*/);
201 m_title
->setTextFormat(Qt::PlainText
);
204 //m_icon->setPaletteBackgroundColor("lightblue");
205 //m_title->setPaletteBackgroundColor("lightyellow");
208 LinkLabel::~LinkLabel()
212 void LinkLabel::setLink(const QString
&title
, const QString
&icon
, LinkLook
*look
)
215 m_look
= look
; // Needed for icon size
217 m_title
->setText(title
);
218 m_title
->setShown( ! title
.isEmpty() );
223 QPixmap pixmap
= DesktopIcon(icon
, m_look
->iconSize(), m_look
->iconSize(), kapp
);
224 if (!pixmap
.isNull())
225 m_icon
->setPixmap(pixmap
);
227 m_icon
->setShown( ! icon
.isEmpty() );
233 void LinkLabel::setLook(LinkLook
*look
) // FIXME: called externaly (so, without setLink()) it's buggy (icon not
238 font
.setBold(look
->bold());
239 font
.setUnderline(look
->underlineOutside());
240 font
.setItalic(look
->italic());
241 m_title
->setFont(font
);
242 m_title
->setPaletteForegroundColor( m_isSelected
? KApplication::palette().active().highlightedText() : look
->effectiveColor() );
244 m_icon
->setShown( m_icon
->pixmap() && ! m_icon
->pixmap()->isNull() );
246 setAlign(m_hAlign
, m_vAlign
);
249 void LinkLabel::setAlign(int hAlign
, int vAlign
)
257 // Define alignment flags :
258 //FIXME TODO: Use directly flags !
259 int hFlag
, vFlag
, wBreak
;
262 case 0: hFlag
= Qt::AlignLeft
; break;
263 case 1: hFlag
= Qt::AlignHCenter
; break;
264 case 2: hFlag
= Qt::AlignRight
; break;
267 case 0: vFlag
= Qt::AlignTop
; break;
269 case 1: vFlag
= Qt::AlignVCenter
; break;
270 case 2: vFlag
= Qt::AlignBottom
; break;
272 wBreak
= Qt::TextWordWrap
* (hAlign
!= 1);
274 // Clear the widget :
275 m_layout
->removeItem(m_spacer1
);
276 m_layout
->remove(m_icon
);
277 m_layout
->remove(m_title
);
278 m_layout
->removeItem(m_spacer2
);
280 // Otherwise, minimumSize will be incoherent (last size ? )
281 m_layout
->setResizeMode(QLayout::Minimum
);
283 // And re-populate the widget with the appropriates things and order
284 bool addSpacers
= hAlign
== 1;
285 m_layout
->setDirection(Q3BoxLayout::LeftToRight
);
286 //m_title->setSizePolicy( QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum/*Expanding*/, 0, 0, false) );
287 m_icon
->setSizePolicy( QSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Preferred
/*Expanding*/, 0, 0, false) );
288 m_spacer1
->changeSize( 0, 0, QSizePolicy::Expanding
, QSizePolicy::Preferred
/*Expanding*/ );
289 m_spacer2
->changeSize( 0, 0, QSizePolicy::Expanding
, QSizePolicy::Preferred
/*Expanding*/ );
291 m_icon
->setAlignment( hFlag
| vFlag
);
292 m_title
->setAlignment( hFlag
| vFlag
| wBreak
);
293 if ( addSpacers
&& (vAlign
!= 0) ||
294 (m_title
->text().isEmpty() && hAlign
== 2) )
295 m_layout
->addItem(m_spacer1
);
296 if (hAlign
== 2) { // If align at right, icon is at right
297 m_layout
->addWidget(m_title
);
298 m_layout
->addWidget(m_icon
);
300 m_layout
->addWidget(m_icon
);
301 m_layout
->addWidget(m_title
);
303 if ( addSpacers
&& (vAlign
!= 2) ||
304 (m_title
->text().isEmpty() && hAlign
== 0) )
305 m_layout
->addItem(m_spacer2
);
308 void LinkLabel::enterEvent(QEvent
*)
311 if ( ! m_isSelected
)
312 m_title
->setPaletteForegroundColor(m_look
->effectiveHoverColor());
314 QFont font
= m_title
->font();
315 font
.setUnderline(m_look
->underlineInside());
316 m_title
->setFont(font
);
319 void LinkLabel::leaveEvent(QEvent
*)
322 if ( ! m_isSelected
)
323 m_title
->setPaletteForegroundColor(m_look
->effectiveColor());
325 QFont font
= m_title
->font();
326 font
.setUnderline(m_look
->underlineOutside());
327 m_title
->setFont(font
);
330 void LinkLabel::setSelected(bool selected
)
332 m_isSelected
= selected
;
334 m_title
->setPaletteForegroundColor(KApplication::palette().active().highlightedText());
335 else if (m_isHovered
)
336 m_title
->setPaletteForegroundColor(m_look
->effectiveHoverColor());
338 m_title
->setPaletteForegroundColor(m_look
->effectiveColor());
341 void LinkLabel::setPaletteBackgroundColor(const QColor
&color
)
343 Q3Frame::setPaletteBackgroundColor(color
);
344 m_title
->setPaletteBackgroundColor(color
);
347 int LinkLabel::heightForWidth(int w
) const
349 int iconS
= (m_icon
->isShown()) ? m_look
->iconSize() : 0; // Icon size
350 int iconW
= iconS
; // Icon width to remove to w
351 int titleH
= (m_title
->isShown()) ? m_title
->heightForWidth(w
- iconW
) : 0; // Title height
353 return (titleH
>= iconS
) ? titleH
: iconS
; // No margin for the moment !
356 QString
LinkLabel::toHtml(const QString
&imageName
)
358 QString begin
= "<font color=" + m_look
->effectiveColor().name() + ">";
359 QString end
= "</font>";
360 if (m_look
->italic()) {
364 if (m_look
->bold()) {
368 if (m_look
->underlineOutside()) {
372 if (m_icon
->pixmap()) {
373 QPixmap
icon(*m_icon
->pixmap());
374 begin
.prepend("<img src=" + imageName
+ " style=\"vertical-align: middle\"> ");
375 Q3MimeSourceFactory::defaultFactory()->setPixmap(imageName
, icon
);
377 Q3MimeSourceFactory::defaultFactory()->setData(imageName
, 0L);
378 return begin
+ Tools::textToHTMLWithoutP(m_title
->text()) + end
;
381 /** class LinkDisplay
384 LinkDisplay::LinkDisplay()
385 : m_title(), m_icon(), m_preview(), m_look(0), m_font(), m_minWidth(0), m_width(0), m_height(0)
389 void LinkDisplay::setLink(const QString
&title
, const QString
&icon
, LinkLook
*look
, const QFont
&font
)
391 setLink(title
, icon
, m_preview
, look
, font
);
394 void LinkDisplay::setLink(const QString
&title
, const QString
&icon
, const QPixmap
&preview
, LinkLook
*look
, const QFont
&font
)
403 int BUTTON_MARGIN
= kapp
->style().pixelMetric(QStyle::PM_ButtonMargin
);
404 int LINK_MARGIN
= BUTTON_MARGIN
+ 2;
406 // Recompute m_minWidth:
407 QRect textRect
= QFontMetrics(labelFont(font
, false)).boundingRect(0, 0, /*width=*/1, 500000, Qt::AlignLeft
| Qt::AlignTop
| Qt::TextWordWrap
, m_title
);
408 int iconPreviewWidth
= qMax(m_look
->iconSize(), (m_look
->previewEnabled() ? m_preview
.width() : 0));
409 m_minWidth
= BUTTON_MARGIN
- 1 + iconPreviewWidth
+ LINK_MARGIN
+ textRect
.width();
410 // Recompute m_maxWidth:
411 textRect
= QFontMetrics(labelFont(font
, false)).boundingRect(0, 0, /*width=*/50000000, 500000, Qt::AlignLeft
| Qt::AlignTop
| Qt::TextWordWrap
, m_title
);
412 m_maxWidth
= BUTTON_MARGIN
- 1 + iconPreviewWidth
+ LINK_MARGIN
+ textRect
.width();
414 if (m_width
< m_minWidth
)
415 setWidth(m_minWidth
);
416 // Recompute m_height:
417 m_height
= heightForWidth(m_width
);
420 void LinkDisplay::setWidth(int width
)
422 if (width
< m_minWidth
)
425 if (width
!= m_width
) {
427 m_height
= heightForWidth(m_width
);
431 /** Paint on @p painter
432 * in (@p x, @p y, @p width, @p height)
433 * using @p colorGroup for the button drawing (if @p isHovered)
434 * and the LinkLook color() for the text,
435 * unless [the LinkLook !color.isValid() and it does not useLinkColor()] or [@p isDefaultColor is false]: in this case it will use @p colorGroup.text().
436 * It will draw the button if @p isIconButtonHovered.
438 void LinkDisplay::paint(QPainter
*painter
, int x
, int y
, int width
, int height
, const QColorGroup
&colorGroup
,
439 bool isDefaultColor
, bool isSelected
, bool isHovered
, bool isIconButtonHovered
) const
441 int BUTTON_MARGIN
= kapp
->style().pixelMetric(QStyle::PM_ButtonMargin
);
442 int LINK_MARGIN
= BUTTON_MARGIN
+ 2;
445 // Load the preview...:
446 if (!isHovered
&& m_look
->previewEnabled() && !m_preview
.isNull())
448 // ... Or the icon (if no preview or if the "Open" icon should be shown):
450 int iconSize
= m_look
->iconSize();
451 QString iconName
= (isHovered
? Global::openNoteIcon() : m_icon
);
452 KIcon::States iconState
= (isIconButtonHovered
? KIcon::ActiveState
: KIconLoader::DefaultState
);
453 pixmap
= kapp
->iconLoader()->loadIcon(iconName
, KIconLoader::Desktop
, iconSize
, iconState
, 0L, /*canReturnNull=*/false);
455 int iconPreviewWidth
= qMax(m_look
->iconSize(), (m_look
->previewEnabled() ? m_preview
.width() : 0));
456 int pixmapX
= (iconPreviewWidth
- pixmap
.width()) / 2;
457 int pixmapY
= (height
- pixmap
.height()) / 2;
458 // Draw the button (if any) and the icon:
460 kapp
->style().drawPrimitive(QStyle::PE_ButtonCommand
, painter
, QRect(-1, -1, iconPreviewWidth
+ 2*BUTTON_MARGIN
, height
+ 2),
461 colorGroup
, QStyle::State_Enabled
| (isIconButtonHovered
? QStyle::Style_MouseOver
: 0));
462 painter
->drawPixmap(x
+ BUTTON_MARGIN
- 1 + pixmapX
, y
+ pixmapY
, pixmap
);
464 // Figure out the text color:
466 painter
->setPen(KGlobalSettings::highlightedTextColor());
467 else if (isIconButtonHovered
)
468 painter
->setPen(m_look
->effectiveHoverColor());
469 else if (!isDefaultColor
|| (!m_look
->color().isValid() && !m_look
->useLinkColor())) // If the color is FORCED or if the link color default to the text color:
470 painter
->setPen(colorGroup
.text());
472 painter
->setPen(m_look
->effectiveColor());
474 painter
->setFont(labelFont(m_font
, isIconButtonHovered
));
475 painter
->drawText(x
+ BUTTON_MARGIN
- 1 + iconPreviewWidth
+ LINK_MARGIN
, y
, width
- BUTTON_MARGIN
+ 1 - iconPreviewWidth
- LINK_MARGIN
, height
,
476 Qt::AlignLeft
| Qt::AlignVCenter
| Qt::TextWordWrap
, m_title
);
479 QPixmap
LinkDisplay::feedbackPixmap(int width
, int height
, const QColorGroup
&colorGroup
, bool isDefaultColor
)
481 int theWidth
= qMin(width
, maxWidth());
482 int theHeight
= qMin(height
, heightForWidth(theWidth
));
483 QPixmap
pixmap(theWidth
, theHeight
);
484 pixmap
.fill(colorGroup
.background());
485 QPainter
painter(&pixmap
);
486 paint(&painter
, 0, 0, theWidth
, theHeight
, colorGroup
, isDefaultColor
,
487 /*isSelected=*/false, /*isHovered=*/false, /*isIconButtonHovered=*/false);
492 bool LinkDisplay::iconButtonAt(const QPoint
&pos
) const
494 int BUTTON_MARGIN
= kapp
->style().pixelMetric(QStyle::PM_ButtonMargin
);
495 // int LINK_MARGIN = BUTTON_MARGIN + 2;
496 int iconPreviewWidth
= qMax(m_look
->iconSize(), (m_look
->previewEnabled() ? m_preview
.width() : 0));
498 return pos
.x() <= BUTTON_MARGIN
- 1 + iconPreviewWidth
+ BUTTON_MARGIN
;
501 QRect
LinkDisplay::iconButtonRect() const
503 int BUTTON_MARGIN
= kapp
->style().pixelMetric(QStyle::PM_ButtonMargin
);
504 // int LINK_MARGIN = BUTTON_MARGIN + 2;
505 int iconPreviewWidth
= qMax(m_look
->iconSize(), (m_look
->previewEnabled() ? m_preview
.width() : 0));
507 return QRect(0, 0, BUTTON_MARGIN
- 1 + iconPreviewWidth
+ BUTTON_MARGIN
, m_height
);
510 QFont
LinkDisplay::labelFont(QFont font
, bool isIconButtonHovered
) const
512 if (m_look
->italic())
513 font
.setItalic(true);
516 if (isIconButtonHovered
) {
517 if (m_look
->underlineInside())
518 font
.setUnderline(true);
520 if (m_look
->underlineOutside())
521 font
.setUnderline(true);
526 int LinkDisplay::heightForWidth(int width
) const
528 int BUTTON_MARGIN
= kapp
->style().pixelMetric(QStyle::PM_ButtonMargin
);
529 int LINK_MARGIN
= BUTTON_MARGIN
+ 2;
530 int iconPreviewWidth
= qMax(m_look
->iconSize(), (m_look
->previewEnabled() ? m_preview
.width() : 0));
531 int iconPreviewHeight
= qMax(m_look
->iconSize(), (m_look
->previewEnabled() ? m_preview
.height() : 0));
533 QRect textRect
= QFontMetrics(labelFont(m_font
, false)).boundingRect(0, 0, width
- BUTTON_MARGIN
+ 1 - iconPreviewWidth
- LINK_MARGIN
, 500000, Qt::AlignLeft
| Qt::AlignTop
| Qt::TextWordWrap
, m_title
);
534 return qMax(textRect
.height(), iconPreviewHeight
+ 2*BUTTON_MARGIN
- 2);
537 QString
LinkDisplay::toHtml(const QString
&/*imageName*/) const
543 QString
LinkDisplay::toHtml(HTMLExporter
*exporter
, const KUrl
&url
, const QString
&title
)
546 if (m_look
->previewEnabled() && !m_preview
.isNull()) {
547 QString fileName
= Tools::fileNameForNewFile("preview_" + url
.fileName() + ".png", exporter
->iconsFolderPath
);
548 QString fullPath
= exporter
->iconsFolderPath
+ fileName
;
549 m_preview
.save(fullPath
, "PNG");
550 linkIcon
= QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"\">")
551 .arg(exporter
->iconsFolderName
+ fileName
, QString::number(m_preview
.width()), QString::number(m_preview
.height()));
553 linkIcon
= exporter
->iconsFolderName
+ exporter
->copyIcon(m_icon
, m_look
->iconSize());
554 linkIcon
= QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"\">")
555 .arg(linkIcon
, QString::number(m_look
->iconSize()), QString::number(m_look
->iconSize()));
558 QString linkTitle
= Tools::textToHTMLWithoutP(title
.isEmpty() ? m_title
: title
);
560 return QString("<a href=\"%1\">%2 %3</a>").arg(url
.prettyUrl(), linkIcon
, linkTitle
);
563 /** LinkLookEditWidget **/
565 LinkLookEditWidget::LinkLookEditWidget(KCModule
*module
, const QString exTitle
, const QString exIcon
,
566 QWidget
*parent
, const char *name
, Qt::WFlags fl
)
567 : QWidget(parent
, name
, fl
)
570 Q3VBoxLayout
*layout
= new Q3VBoxLayout(this, KDialogBase::marginHint(), KDialogBase::spacingHint());
572 m_italic
= new QCheckBox(i18n("I&talic"), this);
573 layout
->addWidget(m_italic
);
575 m_bold
= new QCheckBox(i18n("&Bold"), this);
576 layout
->addWidget(m_bold
);
578 Q3GridLayout
*gl
= new Q3GridLayout(layout
, /*rows=*//*(look->canPreview() ? 5 : 4)*/5, /*columns=*//*3*/4);
579 gl
->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding
), 1, /*2*/3);
581 m_underlining
= new QComboBox(false, this);
582 m_underlining
->insertItem(i18n("Always"));
583 m_underlining
->insertItem(i18n("Never"));
584 m_underlining
->insertItem(i18n("On mouse hovering"));
585 m_underlining
->insertItem(i18n("When mouse is outside"));
586 label
= new QLabel(m_underlining
, i18n("&Underline:"), this);
587 gl
->addWidget(label
, 0, 0);
588 gl
->addWidget(m_underlining
, 0, 1);
590 m_color
= new KColorCombo2(QRgb(), this);
591 label
= new QLabel(m_color
, i18n("Colo&r:"), this);
592 gl
->addWidget(label
, 1, 0);
593 gl
->addWidget(m_color
, 1, 1);
595 m_hoverColor
= new KColorCombo2(QRgb(), this);
596 label
= new QLabel(m_hoverColor
, i18n("&Mouse hover color:"), this);
597 gl
->addWidget(label
, 2, 0);
598 gl
->addWidget(m_hoverColor
, 2, 1);
600 Q3HBoxLayout
*icoLay
= new Q3HBoxLayout(/*parent=*/0L, /*margin=*/0, KDialogBase::spacingHint());
601 m_iconSize
= new IconSizeCombo(false, this);
602 icoLay
->addWidget(m_iconSize
);
603 label
= new QLabel(m_iconSize
, i18n("&Icon size:"), this);
604 gl
->addWidget(label
, 3, 0);
605 gl
->addItem( icoLay
, 3, 1);
607 m_preview
= new QComboBox(false, this);
608 m_preview
->insertItem(i18n("None"));
609 m_preview
->insertItem(i18n("Icon size"));
610 m_preview
->insertItem(i18n("Twice the icon size"));
611 m_preview
->insertItem(i18n("Three times the icon size"));
612 m_label
= new QLabel(m_preview
, i18n("&Preview:"), this);
613 m_hLabel
= new HelpLabel(
614 i18n("You disabled preview but still see images?"),
615 i18n("<p>This is normal because there are several type of notes.<br>"
616 "This setting only applies to file and local link notes.<br>"
617 "The images you see are image notes, not file notes.<br>"
618 "File notes are generic documents, whereas image notes are pictures you can draw in.</p>"
619 "<p>When dropping files to baskets, %1 detects their type and shows you the content of the files.<br>"
620 "For instance, when dropping image or text files, image and text notes are created for them.<br>"
621 "For type of files %2 does not understand, they are shown as generic file notes with just an icon or file preview and a filename.</p>"
622 "<p>If you do not want the application to create notes depending on the content of the files you drop, "
623 "go to the \"General\" page and uncheck \"Image or animation\" in the \"View Content of Added Files for the Following Types\" group.</p>")
624 // TODO: Note: you can resize down maximum size of images...
625 .arg(kapp
->aboutData()->programName(), kapp
->aboutData()->programName()),
627 gl
->addWidget(m_label
, 4, 0);
628 gl
->addWidget(m_preview
, 4, 1);
629 gl
->addMultiCellWidget(m_hLabel
, /*fromRow=*/5, /*toRow=*/5, /*fromCol=*/1, /*toCol*/2);
631 Q3GroupBox
*gb
= new Q3HGroupBox(i18n("Example"), this);
632 m_exLook
= new LinkLook
;
633 m_example
= new LinkLabel(exTitle
, exIcon
, m_exLook
, 1, 1, gb
);
634 m_example
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Expanding
);
635 m_example
->setCursor(QCursor(Qt::PointingHandCursor
));
636 layout
->addWidget(gb
);
640 connect( m_italic
, SIGNAL(stateChanged(int)), this, SLOT(slotChangeLook()) );
641 connect( m_bold
, SIGNAL(stateChanged(int)), this, SLOT(slotChangeLook()) );
642 connect( m_underlining
, SIGNAL(activated(int)), this, SLOT(slotChangeLook()) );
643 connect( m_color
, SIGNAL(changed(const QColor
&)), this, SLOT(slotChangeLook()) );
644 connect( m_hoverColor
, SIGNAL(changed(const QColor
&)), this, SLOT(slotChangeLook()) );
645 connect( m_iconSize
, SIGNAL(activated(int)), this, SLOT(slotChangeLook()) );
646 connect( m_preview
, SIGNAL(activated(int)), this, SLOT(slotChangeLook()) );
648 connect( m_italic
, SIGNAL(stateChanged(int)), module
, SLOT(changed()) );
649 connect( m_bold
, SIGNAL(stateChanged(int)), module
, SLOT(changed()) );
650 connect( m_underlining
, SIGNAL(activated(int)), module
, SLOT(changed()) );
651 connect( m_color
, SIGNAL(changed(const QColor
&)), module
, SLOT(changed()) );
652 connect( m_hoverColor
, SIGNAL(changed(const QColor
&)), module
, SLOT(changed()) );
653 connect( m_iconSize
, SIGNAL(activated(int)), module
, SLOT(changed()) );
654 connect( m_preview
, SIGNAL(activated(int)), module
, SLOT(changed()) );
657 void LinkLookEditWidget::set(LinkLook
*look
)
661 m_italic
->setChecked(look
->italic());
662 m_bold
->setChecked(look
->bold());
663 m_underlining
->setCurrentItem(look
->underlining());
664 m_preview
->setCurrentItem(look
->preview());
665 m_color
->setDefaultColor(m_look
->defaultColor());
666 m_color
->setColor(m_look
->color());
667 m_hoverColor
->setDefaultColor(m_look
->defaultHoverColor());
668 m_hoverColor
->setColor(m_look
->hoverColor());
669 m_iconSize
->setSize(look
->iconSize());
670 m_exLook
= new LinkLook(*look
);
671 m_example
->setLook(m_exLook
);
673 if (!look
->canPreview()) {
674 m_label
->setEnabled(false);
675 m_hLabel
->setEnabled(false);
676 m_preview
->setEnabled(false);
681 void LinkLookEditWidget::slotChangeLook()
683 saveToLook(m_exLook
);
684 m_example
->setLink(m_exTitle
, m_exIcon
, m_exLook
); // and can't reload it at another size
687 LinkLookEditWidget::~LinkLookEditWidget()
691 void LinkLookEditWidget::saveChanges()
696 void LinkLookEditWidget::saveToLook(LinkLook
*look
)
698 look
->setLook( m_italic
->isOn(), m_bold
->isOn(), m_underlining
->currentItem(),
699 m_color
->color(), m_hoverColor
->color(),
700 m_iconSize
->iconSize(), (look
->canPreview() ? m_preview
->currentItem() : LinkLook::None
) );
703 #include "linklabel.moc"