diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dcff78c8..37d2909a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ set(kmailprivate_LIB_SRCS collectionquotapage.cpp collectionquotapage_p.cpp collectionaclpage.cpp + colorlistbox.cpp imapaclattribute.cpp messagehelper.cpp messageinfo.cpp diff --git a/colorlistbox.cpp b/colorlistbox.cpp new file mode 100644 index 000000000..f17805e24 --- /dev/null +++ b/colorlistbox.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 +#include + +#include +#include +#include +#include +#include +#include + +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(); + } 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" diff --git a/colorlistbox.h b/colorlistbox.h new file mode 100644 index 000000000..e9d60dc30 --- /dev/null +++ b/colorlistbox.h @@ -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 +#include +#include +#include +#include + +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 diff --git a/configuredialog.cpp b/configuredialog.cpp index a40e3bfe3..8782afce8 100644 --- a/configuredialog.cpp +++ b/configuredialog.cpp @@ -34,7 +34,7 @@ // other KMail headers: #include "kmkernel.h" #include "simplestringlisteditor.h" -#include +#include "colorlistbox.h" #include "messagesender.h" #include #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++ ) diff --git a/configuredialog_p.h b/configuredialog_p.h index 2b58f9c15..cd1db3c47 100644 --- a/configuredialog_p.h +++ b/configuredialog_p.h @@ -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; };