• 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
  • accounts
accounttreewidget.cpp
Go to the documentation of this file.
1 /*
2  accounttreewidget.cpp - Kopete account tree widget
3 
4  Copyright (c) 2009 by Roman Jarosz <kedgedev@centrum.cz>
5  Kopete (c) 2009 by the Kopete developers <kopete-devel@kde.org>
6 
7  *************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  *************************************************************************
15 */
16 
17 #include "accounttreewidget.h"
18 
19 #include <QDropEvent>
20 #include <kdebug.h>
21 
22 AccountTreeWidget::AccountTreeWidget( QWidget *parent )
23  : QTreeWidget( parent )
24 {
25 }
26 
27 void AccountTreeWidget::dragEnterEvent( QDragEnterEvent *event )
28 {
29  if ( event->source() == this && (event->proposedAction() == Qt::MoveAction || dragDropMode() == QAbstractItemView::InternalMove) )
30  {
31  QList<QTreeWidgetItem*> items = selectedItems();
32  if( items.size() != 1 )
33  return;
34 
35  bool dragingIdentity = !dynamic_cast<KopeteAccountLVI*>(items.first());
36 
37  // Set drop flag based on item we drag
38  if ( dragingIdentity )
39  invisibleRootItem()->setFlags(invisibleRootItem()->flags() | Qt::ItemIsDropEnabled);
40  else
41  invisibleRootItem()->setFlags(invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled);
42 
43  for ( int i = 0; i < this->topLevelItemCount(); i++ )
44  {
45  QTreeWidgetItem* identityItem = this->topLevelItem( i );
46  if ( dragingIdentity )
47  identityItem->setFlags( identityItem->flags() & ~Qt::ItemIsDropEnabled );
48  else
49  identityItem->setFlags( identityItem->flags() | Qt::ItemIsDropEnabled );
50  }
51 
52  QTreeWidget::dragEnterEvent(event);
53  }
54 }
55 
56 void AccountTreeWidget::dropEvent(QDropEvent *event)
57 {
58  KopeteIdentityLVI* dragItem = 0;
59  if( selectedItems().size() == 1 )
60  dragItem = dynamic_cast<KopeteIdentityLVI*>(selectedItems().first());
61 
62  QTreeWidget::dropEvent(event);
63 
64  if ( event->isAccepted() )
65  emit itemPositionChanged();
66 
67  // Expand identity item because it will be collapsed after drag
68  if ( dragItem && !dragItem->isExpanded() )
69  dragItem->setExpanded( true );
70 }
71 
72 #include "accounttreewidget.moc"
accounttreewidget.h
QTreeWidget
QWidget
KopeteIdentityLVI
Definition: accounttreewidget.h:50
AccountTreeWidget::itemPositionChanged
void itemPositionChanged()
AccountTreeWidget::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *event)
Definition: accounttreewidget.cpp:27
QTreeWidgetItem
AccountTreeWidget::AccountTreeWidget
AccountTreeWidget(QWidget *parent=0)
Definition: accounttreewidget.cpp:22
AccountTreeWidget::dropEvent
void dropEvent(QDropEvent *event)
Definition: accounttreewidget.cpp:56
KopeteAccountLVI
Definition: accounttreewidget.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 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