• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDE3Support

  • kde3support
  • kdeui
k3activelabel.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; version 2
7 of the License.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "k3activelabel.h"
21
22#include <Q3SimpleRichText>
23#include <QFocusEvent>
24
25#include <ktoolinvocation.h>
26
27class K3ActiveLabelPrivate
28{
29public:
30 K3ActiveLabelPrivate(K3ActiveLabel *qq);
31
32 void updatePalette();
33
34 K3ActiveLabel *q;
35};
36
37K3ActiveLabelPrivate::K3ActiveLabelPrivate(K3ActiveLabel *qq)
38 : q(qq)
39{
40 q->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
41 q->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
42 q->setFrameStyle(QFrame::NoFrame);
43 q->setFocusPolicy(Qt::TabFocus);
44 updatePalette();
45}
46
47void K3ActiveLabelPrivate::updatePalette()
48{
49 QPalette p = q->palette();
50 p.setBrush(QPalette::Base, p.brush(QPalette::Normal, QPalette::Background));
51 p.setColor(QPalette::Text, p.color(QPalette::Normal, QPalette::Foreground));
52 q->setPalette(p);
53}
54
55K3ActiveLabel::K3ActiveLabel(QWidget * parent)
56 : KTextBrowser(parent),d(new K3ActiveLabelPrivate(this))
57{
58}
59
60K3ActiveLabel::K3ActiveLabel(const QString &text, QWidget * parent)
61 : KTextBrowser(parent),d(new K3ActiveLabelPrivate(this))
62{
63 setHtml(text);
64}
65
66K3ActiveLabel::~K3ActiveLabel()
67{
68 delete d;
69}
70
71void K3ActiveLabel::focusInEvent( QFocusEvent* fe )
72{
73 KTextBrowser::focusInEvent(fe);
74 if(fe->reason() == Qt::TabFocusReason || fe->reason() == Qt::BacktabFocusReason)
75 selectAll();
76}
77
78void K3ActiveLabel::focusOutEvent( QFocusEvent* fe )
79{
80 KTextBrowser::focusOutEvent(fe);
81 if(fe->reason() == Qt::TabFocusReason || fe->reason() == Qt::BacktabFocusReason)
82 selectAll(); //TODO reimplement: deselect text
83}
84
85void K3ActiveLabel::keyPressEvent( QKeyEvent *e )
86{
87 switch ( e->key() )
88 {
89 case Qt::Key_Down:
90 case Qt::Key_Up:
91 case Qt::Key_Left:
92 case Qt::Key_Right:
93 // jump over QTextEdit's key navigation breakage.
94 // we're not interested in keyboard navigation within the text
95 QWidget::keyPressEvent( e );
96 break;
97 default:
98 KTextBrowser::keyPressEvent( e );
99 }
100}
101
102bool K3ActiveLabel::event(QEvent *e)
103{
104 // call the base implementation first so it updates
105 // our palette
106 const bool result = KTextBrowser::event(e);
107 if (e->type() == QEvent::ApplicationPaletteChange) {
108 d->updatePalette();
109 }
110 return result;
111}
112
113QSize K3ActiveLabel::minimumSizeHint() const
114{
115 QSize ms = minimumSize();
116 if ((ms.width() > 0) && (ms.height() > 0))
117 return ms;
118
119 int w = 400;
120 if (ms.width() > 0)
121 w = ms.width();
122
123 QString txt = toHtml();
124 Q3SimpleRichText rt(txt, font());
125 rt.setWidth(w - 2*frameWidth() - 10);
126 w = 10 + rt.widthUsed() + 2*frameWidth();
127 if (w < ms.width())
128 w = ms.width();
129 int h = rt.height() + 2*frameWidth();
130 if ( h < ms.height())
131 h = ms.height();
132
133 return QSize(w, h);
134}
135
136QSize K3ActiveLabel::sizeHint() const
137{
138 return minimumSizeHint();
139}
140
141#include "k3activelabel.moc"
K3ActiveLabel
Label with support for selection and clickable links.
Definition: k3activelabel.h:37
K3ActiveLabel::minimumSizeHint
QSize minimumSizeHint() const
Definition: k3activelabel.cpp:113
K3ActiveLabel::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Definition: k3activelabel.cpp:85
K3ActiveLabel::~K3ActiveLabel
virtual ~K3ActiveLabel()
Definition: k3activelabel.cpp:66
K3ActiveLabel::K3ActiveLabel
K3ActiveLabel(QWidget *parent=0)
Constructor.
Definition: k3activelabel.cpp:55
K3ActiveLabel::event
virtual bool event(QEvent *e)
Definition: k3activelabel.cpp:102
K3ActiveLabel::focusInEvent
virtual void focusInEvent(QFocusEvent *fe)
Definition: k3activelabel.cpp:71
K3ActiveLabel::sizeHint
QSize sizeHint() const
Definition: k3activelabel.cpp:136
K3ActiveLabel::focusOutEvent
virtual void focusOutEvent(QFocusEvent *fe)
Definition: k3activelabel.cpp:78
KTextBrowser
KTextBrowser::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
QEvent
QWidget
k3activelabel.h
ktoolinvocation.h
selectAll
KAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal