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

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • configuredialog
colorlistbox.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of kmail
3  *
4  * Copyright (C) 2000 Espen Sand, espen@kde.org
5  * Copyright (C) 2007 Mathias Soeken, msoeken@tzi.de
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "colorlistbox.h"
24 
25 #include <KColorDialog>
26 #include <KColorMimeData>
27 
28 #include <QDragEnterEvent>
29 #include <QDragLeaveEvent>
30 #include <QDragMoveEvent>
31 #include <QDropEvent>
32 #include <QHeaderView>
33 
34 ColorListBox::ColorListBox( QWidget *parent )
35  : QTreeWidget( parent ), mCurrentOnDragEnter( 0L )
36 {
37  setColumnCount( 1 );
38  setRootIsDecorated( false );
39  header()->hide();
40 
41  connect( this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(newColor(QModelIndex)) );
42  setAcceptDrops( true );
43 }
44 
45 void ColorListBox::addColor( const QString& text, const QColor& color )
46 {
47  QTreeWidgetItem *item = new QTreeWidgetItem( QStringList() << text );
48  item->setData( 0, Qt::DecorationRole, color );
49  addTopLevelItem( item );
50 }
51 
52 void ColorListBox::setColorSilently( int index, const QColor &color )
53 {
54  if (index < model()->rowCount()) {
55  topLevelItem( index )->setData( 0, Qt::DecorationRole, color );
56  }
57 }
58 
59 void ColorListBox::setColor( int index, const QColor &color )
60 {
61  if (index < model()->rowCount()) {
62  topLevelItem( index )->setData( 0, Qt::DecorationRole, color );
63  emit changed();
64  }
65 }
66 
67 QColor ColorListBox::color( int index ) const
68 {
69  if (index < model()->rowCount()) {
70  return topLevelItem( index )->data( 0, Qt::DecorationRole ).value<QColor>();
71  } else {
72  return Qt::black;
73  }
74 }
75 
76 void ColorListBox::newColor( const QModelIndex& index )
77 {
78  if ( !isEnabled() ) {
79  return;
80  }
81 
82  if (index.isValid()) {
83  QColor c = color( index.row() );
84  if (KColorDialog::getColor(c, this) != QDialog::Rejected) {
85  setColor( index.row(), c );
86  }
87  }
88 }
89 
90 void ColorListBox::dragEnterEvent( QDragEnterEvent *e )
91 {
92  if (KColorMimeData::canDecode( e->mimeData() ) && isEnabled()) {
93  mCurrentOnDragEnter = currentItem();
94  e->setAccepted( true );
95  } else {
96  mCurrentOnDragEnter = 0L;
97  e->setAccepted( false );
98  }
99 }
100 
101 
102 void ColorListBox::dragLeaveEvent( QDragLeaveEvent * )
103 {
104  if (mCurrentOnDragEnter) {
105  setCurrentItem( mCurrentOnDragEnter );
106  mCurrentOnDragEnter = 0L;
107  }
108 }
109 
110 
111 void ColorListBox::dragMoveEvent( QDragMoveEvent *e )
112 {
113  if (KColorMimeData::canDecode( e->mimeData() ) && isEnabled()) {
114  QTreeWidgetItem *item = itemAt( e->pos() );
115  if ( item ) {
116  setCurrentItem( item );
117  }
118  }
119 }
120 
121 
122 void ColorListBox::dropEvent( QDropEvent *e )
123 {
124  QColor color = KColorMimeData::fromMimeData( e->mimeData() );
125  if (color.isValid()) {
126  QTreeWidgetItem *item = currentItem();
127  if ( item ) {
128  item->setData( 0, Qt::DecorationRole, color );
129  emit changed();
130  }
131  mCurrentOnDragEnter = 0L;
132  }
133 }
134 
135 #include "colorlistbox.moc"
ColorListBox::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *e)
Definition: colorlistbox.cpp:90
QTreeWidget
text
virtual QByteArray text(quint32 serialNumber) const =0
ColorListBox::dropEvent
void dropEvent(QDropEvent *e)
Definition: colorlistbox.cpp:122
ColorListBox::setColor
void setColor(int index, const QColor &color)
Definition: colorlistbox.cpp:59
QWidget
ColorListBox::dragLeaveEvent
void dragLeaveEvent(QDragLeaveEvent *e)
Definition: colorlistbox.cpp:102
fromMimeData
static MailList fromMimeData(const QMimeData *md)
canDecode
static bool canDecode(const QMimeData *md)
ColorListBox::color
QColor color(int index) const
Definition: colorlistbox.cpp:67
QTreeWidgetItem
colorlistbox.h
ColorListBox::setColorSilently
void setColorSilently(int index, const QColor &color)
Definition: colorlistbox.cpp:52
ColorListBox::dragMoveEvent
void dragMoveEvent(QDragMoveEvent *e)
Definition: colorlistbox.cpp:111
ColorListBox::changed
void changed()
ColorListBox::addColor
void addColor(const QString &text, const QColor &color=Qt::black)
Definition: colorlistbox.cpp:45
ColorListBox::ColorListBox
ColorListBox(QWidget *parent=0)
Definition: colorlistbox.cpp:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • 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