Krazy/EBN: qMin is better than QMIN
[kphotoalbum.git] / MainWindow / BreadcrumbViewer.cpp
blob840e9cb59216a3d01123fda1221c69c240b77299
1 #include "BreadcrumbViewer.h"
2 #include <QTextDocument>
4 void BreadcrumbViewer::setBreadcrumbs( const Browser::BreadcrumbList& list )
6 _activeCrumbs = list.latest();
7 updateText();
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 ) ) );
20 /**
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()
27 QStringList htmlList;
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());
34 QTextDocument doc;
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;
42 doc.setHtml(tmp);
43 if ( doc.size().width() > width() ) {
44 res = ellipses + res;
45 break;
48 // now check that we can fit in ellipses if this was the last token
49 const QString tmp2 = ellipses + tmp;
50 doc.setHtml(tmp2);
51 if ( doc.size().width() > width() && i != 0 ) {
52 // Nope, so better stop here
53 res = ellipses + res;
54 break;
57 res = tmp;
60 setText( res );
64 void BreadcrumbViewer::resizeEvent( QResizeEvent* event )
66 QLabel::resizeEvent( event );
67 updateText();
70 QSize BreadcrumbViewer::minimumSizeHint() const
72 return QSize( 100, QLabel::minimumSizeHint().height() );