Moved KPIM::ColorListBox to kmail/ because KMail

is the only user of this class

svn path=/trunk/KDE/kdepim/; revision=1104688
wilder-work
Tobias Koenig 16 years ago
parent 6241bc73f6
commit 9e5099f318
  1. 1
      CMakeLists.txt
  2. 131
      colorlistbox.cpp
  3. 58
      colorlistbox.h
  4. 4
      configuredialog.cpp
  5. 7
      configuredialog_p.h

@ -57,6 +57,7 @@ set(kmailprivate_LIB_SRCS
collectionquotapage.cpp
collectionquotapage_p.cpp
collectionaclpage.cpp
colorlistbox.cpp
imapaclattribute.cpp
messagehelper.cpp
messageinfo.cpp

@ -0,0 +1,131 @@
/*
* This file is part of libkdepim.
*
* Copyright (C) 2000 Espen Sand, espen@kde.org
* Copyright (C) 2007 Mathias Soeken, msoeken@tzi.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "colorlistbox.h"
#include <KColorDialog>
#include <KColorMimeData>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QHeaderView>
#include <QStringList>
ColorListBox::ColorListBox( QWidget *parent )
: QTreeWidget( parent ), mCurrentOnDragEnter( 0L )
{
setColumnCount( 1 );
setRootIsDecorated( false );
header()->hide();
connect( this, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(newColor(const QModelIndex&)) );
setAcceptDrops( true );
}
void ColorListBox::addColor( const QString& text, const QColor& color )
{
QTreeWidgetItem *item = new QTreeWidgetItem( QStringList() << text );
item->setData( 0, Qt::DecorationRole, color );
addTopLevelItem( item );
}
void ColorListBox::setColor( int index, const QColor &color )
{
if (index < model()->rowCount()) {
topLevelItem( index )->setData( 0, Qt::DecorationRole, color );
emit changed();
}
}
QColor ColorListBox::color( int index ) const
{
if (index < model()->rowCount()) {
return topLevelItem( index )->data( 0, Qt::DecorationRole ).value<QColor>();
} else {
return Qt::black;
}
}
void ColorListBox::newColor( const QModelIndex& index )
{
if( !isEnabled() )
{
return;
}
if (index.isValid()) {
QColor c = color( index.row() );
if (KColorDialog::getColor(c, this) != QDialog::Rejected) {
setColor( index.row(), c );
}
}
}
void ColorListBox::dragEnterEvent( QDragEnterEvent *e )
{
if (KColorMimeData::canDecode( e->mimeData() ) && isEnabled()) {
mCurrentOnDragEnter = currentItem();
e->setAccepted( true );
}
else {
mCurrentOnDragEnter = 0L;
e->setAccepted( false );
}
}
void ColorListBox::dragLeaveEvent( QDragLeaveEvent * )
{
if (mCurrentOnDragEnter) {
setCurrentItem( mCurrentOnDragEnter );
mCurrentOnDragEnter = 0L;
}
}
void ColorListBox::dragMoveEvent( QDragMoveEvent *e )
{
if (KColorMimeData::canDecode( e->mimeData() ) && isEnabled()) {
QTreeWidgetItem *item = itemAt( e->pos() );
if ( item ) {
setCurrentItem( item );
}
}
}
void ColorListBox::dropEvent( QDropEvent *e )
{
QColor color = KColorMimeData::fromMimeData( e->mimeData() );
if (color.isValid()) {
QTreeWidgetItem *item = currentItem();
if ( item ) {
item->setData( 0, Qt::DecorationRole, color );
emit changed();
}
mCurrentOnDragEnter = 0L;
}
}
#include "colorlistbox.moc"

@ -0,0 +1,58 @@
/*
* This file is part of libkdepim.
*
* Copyright (C) 2000 Espen Sand, espen@kde.org
* Copyright (C) 2007 Mathias Soeken, msoeken@tzi.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef COLORLISTBOX_H
#define COLORLISTBOX_H
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QTreeWidget>
class ColorListBox : public QTreeWidget
{
Q_OBJECT
public:
ColorListBox( QWidget *parent=0 );
void addColor( const QString& text, const QColor& color=Qt::black );
void setColor( int index, const QColor &color );
QColor color( int index ) const;
signals:
void changed();
protected:
void dragEnterEvent( QDragEnterEvent *e );
void dragLeaveEvent( QDragLeaveEvent *e );
void dragMoveEvent( QDragMoveEvent *e );
void dropEvent( QDropEvent *e );
private slots:
void newColor( const QModelIndex& index );
private:
QTreeWidgetItem* mCurrentOnDragEnter;
};
#endif

@ -34,7 +34,7 @@
// other KMail headers:
#include "kmkernel.h"
#include "simplestringlisteditor.h"
#include <libkdepim/colorlistbox.h>
#include "colorlistbox.h"
#include "messagesender.h"
#include <kpimidentities/identitymanager.h>
#include "identitylistview.h"
@ -1159,7 +1159,7 @@ AppearancePageColorsTab::AppearancePageColorsTab( QWidget * parent )
this, SLOT( slotEmitChanged( void ) ) );
// color list box:
mColorList = new KPIM::ColorListBox( this );
mColorList = new ColorListBox( this );
mColorList->setEnabled( false ); // since !mCustomColorCheck->isChecked()
QStringList modeList;
for ( int i = 0 ; i < numColorNames ; i++ )

@ -67,6 +67,7 @@ class KFontRequester;
class KIconButton;
class KKeySequenceWidget;
class KComboBox;
class ColorListBox;
namespace MessageList {
namespace Utils {
@ -87,10 +88,6 @@ namespace Kleo {
class CryptoConfig;
}
namespace KPIM {
class ColorListBox;
}
class WarningConfiguration : public QWidget, public Ui::WarningConfiguration
{
public:
@ -374,7 +371,7 @@ private:
private:
QCheckBox *mCustomColorCheck;
KPIM::ColorListBox *mColorList;
ColorListBox *mColorList;
QCheckBox *mRecycleColorCheck;
QSpinBox *mCloseToQuotaThreshold;
};

Loading…
Cancel
Save