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

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • ui
kdhorizontalline.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++ -*-
2  KD Tools - a set of useful widgets for Qt
3 */
4 
5 /****************************************************************************
6 ** Copyright (C) 2005 Klar�vdalens Datakonsult AB. All rights reserved.
7 **
8 ** This file is part of the KD Tools library.
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.GPL included in the
13 ** packaging of this file.
14 **
15 ** Licensees holding valid commercial KD Tools licenses may use this file in
16 ** accordance with the KD Tools Commercial License Agreement provided with
17 ** the Software.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
23 ** information about KD Tools Commercial License Agreements.
24 **
25 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26 ** licensing are not clear to you.
27 **
28 ** In addition, as a special exception, the copyright holders give
29 ** permission to link the code of this program with any edition of the
30 ** Qt library by Trolltech AS, Norway (or with modified versions of Qt
31 ** that use the same license as Qt), and distribute linked
32 ** combinations including the two. You must obey the GNU General
33 ** Public License in all respects for all of the code used other than
34 ** Qt. If you modify this file, you may extend this exception to your
35 ** version of the file, but you are not obligated to do so. If you do
36 ** not wish to do so, delete this exception statement from your
37 ** version.
38 **
39 **********************************************************************/
40 
41 #include "kdhorizontalline.h"
42 
43 #include <QStyle>
44 #include <QPainter>
45 #ifdef QT_ACCESSIBILITY_SUPPORT
46 #include <QAccessible>
47 #endif
48 #include <QFontMetrics>
49 #include <QApplication>
50 #include <QPaintEvent>
51 
52 KDHorizontalLine::KDHorizontalLine( QWidget * parent, const char * name, Qt::WindowFlags f )
53  : QFrame( parent, f ),
54  mAlign( Qt::AlignLeft ),
55  mLenVisible( 0 )
56 {
57  setObjectName( QLatin1String(name) );
58  QFrame::setFrameStyle( HLine | Sunken );
59 }
60 
61 KDHorizontalLine::KDHorizontalLine( const QString & title, QWidget * parent, const char * name, Qt::WindowFlags f )
62  : QFrame( parent, f ),
63  mAlign( Qt::AlignLeft ),
64  mLenVisible( 0 )
65 {
66  setObjectName( QLatin1String(name) );
67  QFrame::setFrameStyle( HLine | Sunken );
68  setTitle( title );
69 }
70 
71 KDHorizontalLine::~KDHorizontalLine() {}
72 
73 void KDHorizontalLine::setFrameStyle( int style ) {
74  QFrame::setFrameStyle( ( style & ~Shape_Mask ) | HLine ); // force HLine
75 }
76 
77 void KDHorizontalLine::setTitle( const QString & title ) {
78  if ( mTitle == title )
79  return;
80  mTitle = title;
81  calculateFrame();
82  update();
83  updateGeometry();
84 #ifdef QT_ACCESSIBILITY_SUPPORT
85  QAccessible::updateAccessibility( this, 0, QAccessible::NameChanged );
86 #endif
87 }
88 
89 void KDHorizontalLine::calculateFrame() {
90  mLenVisible = mTitle.length();
91 #if 0
92  if ( mLenVisible ) {
93  const QFontMetrics fm = fontMetrics();
94  while ( mLenVisible ) {
95  const int tw = fm.width( mTitle, mLenVisible ) + 4*fm.width(QChar(' '));
96  if ( tw < width() )
97  break;
98  mLenVisible--;
99  }
100  qDebug( "mLenVisible = %d (of %d)", mLenVisible, mTitle.length() );
101  if ( mLenVisible ) { // but do we also have a visible label?
102  QRect r = rect();
103  const int va = style().styleHint( QStyle::SH_GroupBox_TextLabelVerticalAlignment, this );
104  if( va & Qt::AlignVCenter )
105  r.setTop( fm.height() / 2 ); // frame rect should be
106  else if( va & Qt::AlignTop )
107  r.setTop( fm.ascent() );
108  setFrameRect( r ); // smaller than client rect
109  return;
110  }
111  }
112  // no visible label
113  setFrameRect( QRect(0,0,0,0) ); // then use client rect
114 #endif
115 }
116 
117 QSizePolicy KDHorizontalLine::sizePolicy() const {
118  return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
119 }
120 
121 QSize KDHorizontalLine::sizeHint() const {
122  return minimumSizeHint();
123 }
124 
125 QSize KDHorizontalLine::minimumSizeHint() const {
126  const int w = fontMetrics().width( mTitle, mLenVisible ) +
127  fontMetrics().width( QLatin1Char( ' ' ) );
128  const int h = fontMetrics().height();
129  return QSize( qMax( w, indentHint() ), h ).expandedTo( qApp->globalStrut() );
130 }
131 
132 void KDHorizontalLine::paintEvent( QPaintEvent * e ) {
133  QPainter paint( this );
134 
135  if ( mLenVisible ) { // draw title
136  const QFontMetrics & fm = paint.fontMetrics();
137  const int h = fm.height();
138  const int tw = fm.width( mTitle, mLenVisible ) + fm.width(QLatin1Char(' '));
139  int x;
140  if ( mAlign & Qt::AlignHCenter ) // center alignment
141  x = frameRect().width()/2 - tw/2;
142  else if ( mAlign & Qt::AlignRight ) // right alignment
143  x = frameRect().width() - tw;
144  else if ( mAlign & Qt::AlignLeft ) // left alignment
145  x = 0;
146  else { // auto align
147  if( QApplication::isRightToLeft() )
148  x = frameRect().width() - tw;
149  else
150  x = 0;
151  }
152  QRect r( x, 0, tw, h );
153  int va = style()->styleHint( QStyle::SH_GroupBox_TextLabelVerticalAlignment, 0, this );
154  if ( va & Qt::AlignTop )
155  r.translate( 0, fm.descent() );
156  const QColor pen( (QRgb) style()->styleHint( QStyle::SH_GroupBox_TextLabelColor, 0, this ) );
157  if ( !style()->styleHint( QStyle::SH_UnderlineShortcut, 0, this ) )
158  va |= Qt::TextHideMnemonic;
159  style()->drawItemText( &paint, r, Qt::TextShowMnemonic | Qt::AlignHCenter | va, palette(),
160  isEnabled(), mTitle );
161  paint.setClipRegion( e->region().subtract( r ) ); // clip everything but title
162  }
163  drawFrame( &paint );
164 }
165 
166 // static
167 int KDHorizontalLine::indentHint() {
168  return 30;
169 }
170 
171 #include "kdhorizontalline.moc"
KDHorizontalLine::minimumSizeHint
QSize minimumSizeHint() const
Definition: kdhorizontalline.cpp:125
name
const char * name
Definition: kconfigbasedkeyfilter.cpp:124
KDHorizontalLine::KDHorizontalLine
KDHorizontalLine(QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0)
Definition: kdhorizontalline.cpp:52
KDHorizontalLine::setTitle
virtual void setTitle(const QString &title)
Definition: kdhorizontalline.cpp:77
KDHorizontalLine::~KDHorizontalLine
~KDHorizontalLine()
Definition: kdhorizontalline.cpp:71
QWidget
QString
KDHorizontalLine::sizeHint
QSize sizeHint() const
Definition: kdhorizontalline.cpp:121
KDHorizontalLine::paintEvent
void paintEvent(QPaintEvent *)
Definition: kdhorizontalline.cpp:132
KDHorizontalLine::setFrameStyle
void setFrameStyle(int style)
Definition: kdhorizontalline.cpp:73
KDHorizontalLine::title
QString title() const
Definition: kdhorizontalline.h:56
KDHorizontalLine::indentHint
static int indentHint()
Definition: kdhorizontalline.cpp:167
kdhorizontalline.h
KDHorizontalLine::sizePolicy
QSizePolicy sizePolicy() const
Definition: kdhorizontalline.cpp:117
QFrame
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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