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

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • modes
linkslabel.cpp
Go to the documentation of this file.
1 // Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
2 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301 USA
17 
18 
19 #include "linkslabel.h"
20 #include "linkslabel.moc"
21 
22 #include <qlabel.h>
23 #include <kurllabel.h>
24 #include <qlayout.h>
25 
26 #include <vector>
27 #include <algorithm>
28 #include <functional>
29 
30 #include <assert.h>
31 using namespace std;
32 
33 class LinksLabel::Private
34 {
35 public:
36  QHBoxLayout* layout;
37  std::vector<QLabel*> labels;
38  std::vector<KUrlLabel*> urllabels;
39 };
40 
41 LinksLabel::LinksLabel( QWidget* parent )
42  : QWidget( parent )
43 {
44  p = new Private;
45  p->layout = new QHBoxLayout( this );
46 
47  QLabel* l = new QLabel( QString::fromUtf8( "Dit is een " ), this );
48  p->labels.push_back( l );
49  p->layout->addWidget( l );
50 
51  KUrlLabel* u = new KUrlLabel( QString::fromUtf8( "http://www.kde.org/" ),
52  QString::fromUtf8( "url"), this );
53  p->urllabels.push_back( u );
54  p->layout->addWidget( u );
55 
56  l = new QLabel( QString::fromUtf8( " !" ), this );
57  p->labels.push_back( l );
58  p->layout->addWidget(l );
59 
60  p->layout->activate();
61 }
62 
63 LinksLabel::~LinksLabel()
64 {
65  delete p;
66 }
67 
68 void LinksLabel::urlClicked()
69 {
70  const QObject* o = sender();
71  std::vector<KUrlLabel*>::iterator i = std::find( p->urllabels.begin(), p->urllabels.end(), static_cast<const KUrlLabel*>( o ) );
72  assert( i != p->urllabels.end() );
73  emit linkClicked( i - p->urllabels.begin() );
74 }
75 
76 LinksLabel::LinksLabelEditBuf LinksLabel::startEdit()
77 {
78  return LinksLabelEditBuf();
79 }
80 
81 void LinksLabel::addText( const QString& s, LinksLabelEditBuf& buf )
82 {
83  buf.data.push_back( std::pair<bool, QString>( false, s ) );
84 }
85 
86 void LinksLabel::addLink( const QString& s, LinksLabelEditBuf& buf )
87 {
88  buf.data.push_back( std::pair<bool, QString>( true, s ) );
89 }
90 
91 namespace {
92  void deleteObj( QObject* o ) { delete o; }
93 }
94 
95 void LinksLabel::applyEdit( LinksLabelEditBuf& buf )
96 {
97  std::for_each( p->urllabels.begin(), p->urllabels.end(), deleteObj );
98  std::for_each( p->labels.begin(), p->labels.end(), deleteObj );
99  p->urllabels.clear();
100  p->labels.clear();
101 
102  delete p->layout;
103  p->layout = new QHBoxLayout( this );
104 
105  for ( LinksLabelEditBuf::vec::iterator i = buf.data.begin(); i != buf.data.end(); ++i )
106  {
107  if ( i->first )
108  {
109  // we need a KUrlLabel...
110  // the url is an unused stub...
111  KUrlLabel* l = new KUrlLabel( QString::fromUtf8( "http://edu.kde.org/kig" ),
112  i->second, this );
113  p->urllabels.push_back( l );
114  p->layout->addWidget( l );
115  connect( l, SIGNAL( leftClickedUrl() ), SLOT( urlClicked() ) );
116  }
117  else
118  {
119  // we need a normal label...
120  QLabel* l = new QLabel( i->second, this );
121  p->labels.push_back( l );
122  p->layout->addWidget( l );
123  };
124  };
125 
126  QSpacerItem* spacer = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
127 
128  p->layout->addItem( spacer );
129 
130  p->layout->activate();
131 
132  std::for_each( p->urllabels.begin(), p->urllabels.end(), mem_fun( &QWidget::show ) );
133  std::for_each( p->labels.begin(), p->labels.end(), mem_fun( &QWidget::show ) );
134 
135  emit changed();
136 }
LinksLabel::applyEdit
void applyEdit(LinksLabelEditBuf &buf)
apply the changes...
Definition: linkslabel.cpp:95
QWidget
LinksLabel::linkClicked
void linkClicked(int i)
the user clicked on a link.
LinksLabel::addLink
void addLink(const QString &s, LinksLabelEditBuf &buf)
add a link...
Definition: linkslabel.cpp:86
LinksLabel::LinksLabel
LinksLabel(QWidget *parent=0)
Definition: linkslabel.cpp:41
linkslabel.h
LinksLabel::~LinksLabel
~LinksLabel()
Definition: linkslabel.cpp:63
LinksLabel::startEdit
LinksLabelEditBuf startEdit()
start editing, start recording changes in a LinksLabelEditBuf, but don't apply them until after endEd...
Definition: linkslabel.cpp:76
LinksLabel::LinksLabelEditBuf
Definition: linkslabel.h:38
LinksLabel::changed
void changed()
the structure of links and texts was changed
LinksLabel::addText
void addText(const QString &s, LinksLabelEditBuf &buf)
add a piece of normal text.
Definition: linkslabel.cpp:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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