summaryrefslogtreecommitdiffstats
path: root/kig/modes/linkslabel.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 (patch)
treed3bb9f5d25a2dc09ca81adecf39621d871534297 /kig/modes/linkslabel.cpp
downloadtdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.tar.gz
tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kig/modes/linkslabel.cpp')
-rw-r--r--kig/modes/linkslabel.cpp134
1 files changed, 134 insertions, 0 deletions
diff --git a/kig/modes/linkslabel.cpp b/kig/modes/linkslabel.cpp
new file mode 100644
index 00000000..572c0bf8
--- /dev/null
+++ b/kig/modes/linkslabel.cpp
@@ -0,0 +1,134 @@
+// Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
+
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301 USA
+
+
+#include "linkslabel.h"
+#include "linkslabel.moc"
+
+#include <qlabel.h>
+#include <kurllabel.h>
+#include <qlayout.h>
+
+#include <vector>
+#include <algorithm>
+#include <functional>
+
+#include <assert.h>
+using namespace std;
+
+class LinksLabel::Private
+{
+public:
+ QHBoxLayout* layout;
+ std::vector<QLabel*> labels;
+ std::vector<KURLLabel*> urllabels;
+};
+
+LinksLabel::LinksLabel( QWidget* parent, const char* name )
+ : QWidget( parent, name )
+{
+ p = new Private;
+ p->layout = new QHBoxLayout( this );
+
+ QLabel* l = new QLabel( QString::fromUtf8( "Dit is een " ), this );
+ p->labels.push_back( l );
+ p->layout->addWidget( l );
+
+ KURLLabel* u = new KURLLabel( QString::fromUtf8( "http://www.kde.org/" ),
+ QString::fromUtf8( "url"), this );
+ p->urllabels.push_back( u );
+ p->layout->addWidget( u );
+
+ l = new QLabel( QString::fromUtf8( " !" ), this );
+ p->labels.push_back( l );
+ p->layout->addWidget(l );
+
+ p->layout->activate();
+}
+
+LinksLabel::~LinksLabel()
+{
+ delete p;
+}
+
+void LinksLabel::urlClicked()
+{
+ const QObject* o = sender();
+ std::vector<KURLLabel*>::iterator i = std::find( p->urllabels.begin(), p->urllabels.end(), static_cast<const KURLLabel*>( o ) );
+ assert( i != p->urllabels.end() );
+ emit linkClicked( i - p->urllabels.begin() );
+}
+
+LinksLabel::LinksLabelEditBuf LinksLabel::startEdit()
+{
+ return LinksLabelEditBuf();
+}
+
+void LinksLabel::addText( const QString& s, LinksLabelEditBuf& buf )
+{
+ buf.data.push_back( std::pair<bool, QString>( false, s ) );
+}
+
+void LinksLabel::addLink( const QString& s, LinksLabelEditBuf& buf )
+{
+ buf.data.push_back( std::pair<bool, QString>( true, s ) );
+}
+
+namespace {
+ void deleteObj( QObject* o ) { delete o; }
+}
+
+void LinksLabel::applyEdit( LinksLabelEditBuf& buf )
+{
+ std::for_each( p->urllabels.begin(), p->urllabels.end(), deleteObj );
+ std::for_each( p->labels.begin(), p->labels.end(), deleteObj );
+ p->urllabels.clear();
+ p->labels.clear();
+
+ delete p->layout;
+ p->layout = new QHBoxLayout( this );
+
+ for ( LinksLabelEditBuf::vec::iterator i = buf.data.begin(); i != buf.data.end(); ++i )
+ {
+ if ( i->first )
+ {
+ // we need a KURLLabel...
+ // the url is an unused stub...
+ KURLLabel* l = new KURLLabel( QString::fromUtf8( "http://edu.kde.org/kig" ),
+ i->second, this );
+ p->urllabels.push_back( l );
+ p->layout->addWidget( l );
+ connect( l, SIGNAL( leftClickedURL() ), SLOT( urlClicked() ) );
+ }
+ else
+ {
+ // we need a normal label...
+ QLabel* l = new QLabel( i->second, this );
+ p->labels.push_back( l );
+ p->layout->addWidget( l );
+ };
+ };
+
+ QSpacerItem* spacer = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
+
+ p->layout->addItem( spacer );
+
+ p->layout->activate();
+
+ std::for_each( p->urllabels.begin(), p->urllabels.end(), mem_fun( &QWidget::show ) );
+ std::for_each( p->labels.begin(), p->labels.end(), mem_fun( &QWidget::show ) );
+}