1 #include "BreadcrumbViewer.h"
2 #include <QTextDocument>
4 void BreadcrumbViewer::setBreadcrumbs( const Browser::BreadcrumbList
& list
)
6 _activeCrumbs
= list
.latest();
10 void BreadcrumbViewer::linkClicked( const QString
& link
)
12 emit
widenToBreadcrumb( _activeCrumbs
[ link
.toInt() ] );
15 BreadcrumbViewer::BreadcrumbViewer()
17 connect( this, SIGNAL( linkActivated( QString
) ), this, SLOT( linkClicked( QString
) ) );
21 * Format the text with hyperlinks. The tricky part is to handle the situation where all the text doesn't fit in.
22 * The by far best solution would be to compress at a letter level, but this code is really only used in the rare
23 * situation where the user chooses a very long path, as his window usually is somewhat wide.
25 void BreadcrumbViewer::updateText()
29 for ( int i
= 0; i
< _activeCrumbs
.count()-1; ++i
)
30 htmlList
.append( QString::fromLatin1("<a href=\"%1\">%2</a>").arg(i
).arg(_activeCrumbs
[i
].text()) );
31 if ( !_activeCrumbs
[_activeCrumbs
.count()-1].isView() )
32 htmlList
.append(_activeCrumbs
[_activeCrumbs
.count()-1].text());
35 doc
.setDefaultFont( font() );
37 QString res
= htmlList
.last();
38 const QString ellipses
= QChar(0x2026) + QString::fromLatin1(" > ");
39 for ( int i
= htmlList
.count()-2; i
>= 0; --i
) {
40 // If we can't fit it in, then add ellipses
41 const QString tmp
= htmlList
[i
] + QString::fromLatin1(" > ") + res
;
43 if ( doc
.size().width() > width() ) {
48 // now check that we can fit in ellipses if this was the last token
49 const QString tmp2
= ellipses
+ tmp
;
51 if ( doc
.size().width() > width() && i
!= 0 ) {
52 // Nope, so better stop here
64 void BreadcrumbViewer::resizeEvent( QResizeEvent
* event
)
66 QLabel::resizeEvent( event
);
70 QSize
BreadcrumbViewer::minimumSizeHint() const
72 return QSize( 100, QLabel::minimumSizeHint().height() );