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

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
  • config
  • appearance
  • layout
Token.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2008 Teo Mrnjavac <teo.mrnjavac@gmail.com> *
3  * 2008-2009 Seb Ruiz <ruiz@kde.org> *
4  * 2009 Roman Jarosz <kedgedev@gmail.com> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18  ******************************************************************************/
19 
20 #include "Token.h"
21 
22 #include <KColorScheme>
23 #include <QHBoxLayout>
24 #include <QPainter>
25 #include <QPen>
26 
27 #include "TokenDropTarget.h"
28 
29 Token * TokenFactory::createToken(const QString & text, const QString & iconName, int value, QWidget * parent)
30 {
31  return new Token( text, iconName, value, parent );
32 }
33 
34 
35 Token::Token( const QString &name, const QString &iconName, int value, QWidget *parent )
36  : QWidget( parent )
37  , m_name( name )
38  , m_icon( KIcon( iconName ) )
39  , m_iconName( iconName )
40  , m_value( value )
41 {
42  setAttribute( Qt::WA_Hover );
43  if ( parent )
44  {
45  if ( TokenDropTarget *editWidget = qobject_cast<TokenDropTarget*>( parent ) )
46  connect( this, SIGNAL(changed()), editWidget, SIGNAL(changed()) );
47  }
48 
49  m_label = new QLabel( this );
50  m_label->setAlignment( Qt::AlignCenter );
51  m_label->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
52  m_label->setText( name );
53 
54  QHBoxLayout *hlayout = new QHBoxLayout( this );
55  setLayout( hlayout );
56 
57  m_iconContainer = new QLabel( this );
58  m_iconContainer->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
59  QPixmap pixmap = QPixmap( icon().pixmap( 16, 16 ) );
60  m_iconContainer->setPixmap( pixmap );
61 
62  setContentsMargins( 4, 2, 4, 2 );
63 
64  hlayout->setContentsMargins( 0, 0, 0, 0 );
65  hlayout->addWidget( m_iconContainer );
66  hlayout->addWidget( m_label );
67 
68  QFontMetrics metric( font() );
69  QSize size = metric.size( Qt::TextSingleLine, m_label->text() );
70  QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
71  m_label->setSizePolicy( sizePolicy );
72 
73  m_iconContainer->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
74 }
75 
76 QString
77 Token::name() const
78 {
79  return m_name;
80 }
81 
82 int
83 Token::value() const
84 {
85  return m_value;
86 }
87 
88 KIcon
89 Token::icon() const
90 {
91  return m_icon;
92 }
93 
94 QString Token::iconName() const
95 {
96  return m_iconName;
97 }
98 
99 void Token::paintEvent(QPaintEvent *pe)
100 {
101  Q_UNUSED( pe )
102 
103  QPainter p( this );
104  p.setBrush( Qt::NoBrush );
105  p.setRenderHint( QPainter::Antialiasing );
106  QColor c;
107  if ( hasFocus() )
108  {
109  c = KColorScheme( QPalette::Active ).decoration( KColorScheme::HoverColor ).color();
110  }
111  else
112  {
113  c = palette().color( foregroundRole() );
114  c.setAlpha( c.alpha() * 0.5 );
115  }
116  p.setPen( QPen( c, 2 ) );
117  p.drawRoundedRect( rect().adjusted(1,1,-1,-1), 4, 4 );
118  p.end();
119 }
120 
121 
Token::m_value
int m_value
Definition: Token.h:62
Token::changed
void changed()
QWidget
Token::m_label
QLabel * m_label
Definition: Token.h:65
Token::value
int value() const
Definition: Token.cpp:83
TokenDropTarget
Definition: TokenDropTarget.h:32
Token::name
QString name() const
Definition: Token.cpp:77
Token::m_icon
KIcon m_icon
Definition: Token.h:60
Token::icon
KIcon icon() const
Definition: Token.cpp:89
TokenDropTarget.h
Token::m_name
QString m_name
Definition: Token.h:59
Token::paintEvent
virtual void paintEvent(QPaintEvent *pe)
Definition: Token.cpp:99
Token::m_iconContainer
QLabel * m_iconContainer
Definition: Token.h:64
QLabel
TokenFactory::createToken
virtual Token * createToken(const QString &text, const QString &iconName, int value, QWidget *parent=0)
Definition: Token.cpp:29
Token
Definition: Token.h:38
Token::iconName
QString iconName() const
Definition: Token.cpp:94
Token::m_iconName
QString m_iconName
Definition: Token.h:61
Token.h
Token::Token
Token(const QString &text, const QString &iconName, int value, QWidget *parent=0)
Definition: Token.cpp:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

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