]> cloud.milkyroute.net Git - dolphin.git/blob - src/metatextlabel.cpp
- Fix crash found while investigating https://bugs.kde.org/show_bug.cgi?id=170927
[dolphin.git] / src / metatextlabel.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "metatextlabel.h"
21
22 #include <kglobalsettings.h>
23 #include <klocale.h>
24 #include <kvbox.h>
25
26 #include <QHBoxLayout>
27 #include <QLabel>
28
29 MetaTextLabel::MetaTextLabel(QWidget* parent) :
30 QWidget(parent),
31 m_lines(0),
32 m_layout(0)
33 {
34 }
35
36 MetaTextLabel::~MetaTextLabel()
37 {
38 }
39
40 void MetaTextLabel::clear()
41 {
42 if (m_layout != 0) {
43 m_layout->removeWidget(m_lines);
44 }
45
46 delete m_lines;
47 m_lines = 0;
48
49 delete m_layout;
50 m_layout = 0;
51 }
52
53 void MetaTextLabel::add(const QString& labelText, const QString& infoText)
54 {
55 if (m_lines == 0) {
56 Q_ASSERT(m_layout == 0);
57
58 m_lines = new KVBox(this);
59 m_layout = new QHBoxLayout();
60 m_layout->addWidget(m_lines);
61 setLayout(m_layout);
62
63 m_lines->show();
64 }
65
66 QWidget* line = new QWidget(m_lines);
67
68 QLabel* label = new QLabel(labelText, line);
69 label->setFont(KGlobalSettings::smallestReadableFont());
70 label->setAlignment(Qt::AlignRight | Qt::AlignTop);
71
72 QPalette palette = label->palette();
73 QColor foreground = palette.color(QPalette::Foreground);
74 foreground.setAlpha(128);
75 palette.setColor(QPalette::Foreground, foreground);
76 label->setPalette(palette);
77
78 QLabel* info = new QLabel(infoText, line);
79 info->setFont(KGlobalSettings::smallestReadableFont());
80 info->setAlignment(Qt::AlignLeft | Qt::AlignTop);
81 info->setWordWrap(true);
82
83 QHBoxLayout* layout = new QHBoxLayout(line);
84 layout->setMargin(2);
85 layout->addWidget(label, 50);
86 layout->addWidget(info, 50);
87
88 line->show();
89 }
90
91 #include "metatextlabel.moc"