forked from shundhammer/qdirstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreadcrumbNavigator.cpp
99 lines (73 loc) · 2.35 KB
/
BreadcrumbNavigator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* File name: BreadcrumbNavigator.cpp
* Summary: Breadcrumb widget for QDirStat
* License: GPL V2 - See file LICENSE for details.
*
* Author: Stefan Hundhammer <[email protected]>
*/
#include "Qt4Compat.h" // qHtmlEscape()
#include "BreadcrumbNavigator.h"
#include "Logger.h"
using namespace QDirStat;
BreadcrumbNavigator::BreadcrumbNavigator( QWidget * parent ):
QLabel( parent )
{
clear();
setTextFormat( Qt::RichText );
connect( this, SIGNAL( linkActivated ( QString ) ),
this, SLOT ( logPathClicked( QString ) ) );
connect( this, SIGNAL( linkActivated ( QString ) ),
this, SIGNAL( pathClicked ( QString ) ) );
}
BreadcrumbNavigator::~BreadcrumbNavigator()
{
// NOP
}
void BreadcrumbNavigator::setPath( FileInfo * item )
{
QString html;
while ( item )
{
// Stop at the DirTree's <root> pseudo item
if ( item->tree() && item == item->tree()->root() )
break;
if ( item->isDirInfo() )
{
QString basePath;
QString name;
if ( item->isDotEntry() )
name = FileInfo::dotEntryName();
else
splitBasePath( item->name(), basePath, name );
QString href= QString( "<a href=\"%1\">%2</a>" )
.arg( item->debugUrl() )
.arg( qHtmlEscape( name ) );
if ( name != "/" )
href += "/";
html = qHtmlEscape( basePath ) + href + html;
}
item = item->parent();
}
setText( html );
}
void BreadcrumbNavigator::splitBasePath( const QString & path,
QString & basePath_ret, // return parameter
QString & name_ret ) // return parameter
{
basePath_ret = "";
name_ret = path;
if ( path != "/" && path.contains( "/" ) )
{
QStringList components = path.split( "/", QString::SkipEmptyParts );
if ( ! components.empty() )
name_ret = components.takeLast();
if ( ! components.empty() )
basePath_ret = components.join( "/" ) + "/";
if ( path.startsWith( "/" ) )
basePath_ret.prepend( "/" );
}
}
void BreadcrumbNavigator::logPathClicked( const QString & path )
{
logInfo() << "Clicked path " << path << endl;
}