ruphy / raptor

menu for KDE 4

This URL has Read+Write access

Bruno Abinader (author)
Wed Apr 22 06:36:10 -0700 2009
ruphy (committer)
Sun Apr 26 10:35:37 -0700 2009
commit  df842236d9366e59e865755d9607be8238e6b761
tree    f96f3872cab7ba81435a548f854967ccb6c6bf08
parent  e38ce28d01f4b3f17716e545a4429e7470ec225c
raptor / view / breadcrumbitem.cpp
100644 137 lines (109 sloc) 2.677 kb
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* This file is part of the KDE project
 
Copyright (C) 2009 Alessandro Diaferia <alediaferia@gmail.com>
Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "breadcrumbitem.h"
#include "breadcrumb.h"
 
#include <QModelIndex>
#include <QRectF>
#include <QFontMetrics>
#include <QTimeLine>
#include <QPainter>
 
#include <KIcon>
#include <KLocale>
#include <KGlobalSettings>
 
#include <Plasma/Theme>
#include <Plasma/Svg>
 
BreadcrumbItem::BreadcrumbItem(const QModelIndex &index) : m_arrow(false), m_mainMenu(false), m_textWidth(-1), m_showingText(false), m_svg(0)
{
    if (!index.isValid()) {
        m_arrow = true;
        m_svg = new Plasma::Svg;
        m_svg->setImagePath("widgets/raptorarrows");
        m_svg->setContainsMultipleImages(true);
        return;
    }
 
    m_index = index;
}
 
BreadcrumbItem::~BreadcrumbItem()
{
    delete m_svg;
}
 
QString BreadcrumbItem::name() const
{
    if (m_arrow) {
        return QString();
    }
 
    if (m_mainMenu) {
        return i18n("Main Menu");
    }
 
    return m_index.data().toString();
}
 
QPixmap BreadcrumbItem::icon(int size) const
{
    if (m_arrow) {
        QPixmap pixmap(size, size);
        pixmap.fill(Qt::transparent);
 
        m_svg->resize(size, size);
 
        QPainter p(&pixmap);
        m_svg->paint(&p, size / 4, size / 4, "rightarrow");
        p.end();
 
        return pixmap;
    }
    if (m_mainMenu) {
        return KIcon("go-home").pixmap(size, size);
    }
 
    return m_index.data(Qt::DecorationRole).value<QIcon>().pixmap(size, size);
}
 
void BreadcrumbItem::setRect(const QRectF &rect)
{
    m_rect = rect;
}
 
QRectF BreadcrumbItem::rect() const
{
    return m_rect;
}
 
bool BreadcrumbItem::isArrow()
{
    return m_arrow;
}
 
void BreadcrumbItem::setIsMainMenu(bool set)
{
    m_mainMenu = set;
    m_arrow = !set;
}
 
bool BreadcrumbItem::isMainMenu()
{
    return m_mainMenu;
}
 
QModelIndex BreadcrumbItem::index() const
{
    return m_index;
}
 
int BreadcrumbItem::textWidth()
{
    if (m_textWidth == -1) {
        m_textWidth = Plasma::Theme::defaultTheme()->fontMetrics().width(name());
    }
    return m_textWidth;
}
 
bool BreadcrumbItem::showingText()
{
     return m_showingText;
}
 
void BreadcrumbItem::setShowingText(bool set)
{
    m_showingText = set;
}
 
void BreadcrumbItem::setTextRect(const QRectF &rect)
{
    m_textRect = rect;
}
 
QRectF BreadcrumbItem::textRect() const
{
    return m_textRect;
}