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

KDE3Support

  • sources
  • kde-4.14
  • kdelibs
  • 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 
27 class K3ActiveLabelPrivate
28 {
29 public:
30  K3ActiveLabelPrivate(K3ActiveLabel *qq);
31 
32  void updatePalette();
33 
34  K3ActiveLabel *q;
35 };
36 
37 K3ActiveLabelPrivate::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 
47 void 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 
55 K3ActiveLabel::K3ActiveLabel(QWidget * parent)
56  : KTextBrowser(parent),d(new K3ActiveLabelPrivate(this))
57 {
58 }
59 
60 K3ActiveLabel::K3ActiveLabel(const QString &text, QWidget * parent)
61  : KTextBrowser(parent),d(new K3ActiveLabelPrivate(this))
62 {
63  setHtml(text);
64 }
65 
66 K3ActiveLabel::~K3ActiveLabel()
67 {
68  delete d;
69 }
70 
71 void K3ActiveLabel::focusInEvent( QFocusEvent* fe )
72 {
73  KTextBrowser::focusInEvent(fe);
74  if(fe->reason() == Qt::TabFocusReason || fe->reason() == Qt::BacktabFocusReason)
75  selectAll();
76 }
77 
78 void 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 
85 void 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 
102 bool 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 
113 QSize 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 
136 QSize K3ActiveLabel::sizeHint() const
137 {
138  return minimumSizeHint();
139 }
140 
141 #include "k3activelabel.moc"
QPalette::setBrush
void setBrush(ColorRole role, const QBrush &brush)
Q3SimpleRichText
QEvent
QWidget
KTextBrowser::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
QEvent::type
Type type() const
QSize::width
int width() const
K3ActiveLabel::~K3ActiveLabel
virtual ~K3ActiveLabel()
Definition: k3activelabel.cpp:66
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QTextBrowser::focusOutEvent
virtual void focusOutEvent(QFocusEvent *ev)
QTextEdit::setHtml
void setHtml(const QString &text)
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
Q3SimpleRichText::height
int height() const
Q3SimpleRichText::widthUsed
int widthUsed() const
QTextEdit::focusInEvent
virtual void focusInEvent(QFocusEvent *e)
K3ActiveLabel::K3ActiveLabel
K3ActiveLabel(QWidget *parent=0)
Constructor.
Definition: k3activelabel.cpp:55
ktoolinvocation.h
QTextEdit::selectAll
void selectAll()
QWidget::minimumSize
QSize minimumSize() const
QFocusEvent::reason
Qt::FocusReason reason() const
QPalette::brush
const QBrush & brush(ColorGroup group, ColorRole role) const
K3ActiveLabel
Label with support for selection and clickable links.
Definition: k3activelabel.h:36
K3ActiveLabel::focusOutEvent
virtual void focusOutEvent(QFocusEvent *fe)
Definition: k3activelabel.cpp:78
QString
Q3SimpleRichText::setWidth
void setWidth(int w)
QKeyEvent::key
int key() const
QSize
QWidget::font
const QFont & font() const
KTextBrowser
K3ActiveLabel::minimumSizeHint
QSize minimumSizeHint() const
Definition: k3activelabel.cpp:113
QKeyEvent
QFrame::frameWidth
int frameWidth() const
QTextBrowser::event
virtual bool event(QEvent *e)
QSize::height
int height() const
QWidget::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
K3ActiveLabel::focusInEvent
virtual void focusInEvent(QFocusEvent *fe)
Definition: k3activelabel.cpp:71
K3ActiveLabel::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Definition: k3activelabel.cpp:85
K3ActiveLabel::sizeHint
QSize sizeHint() const
Definition: k3activelabel.cpp:136
k3activelabel.h
QFocusEvent
K3ActiveLabel::event
virtual bool event(QEvent *e)
Definition: k3activelabel.cpp:102
QPalette
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:47 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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