-rw-r--r-- | libkdepim/categoryselectdialog.cpp | 70 | ||||
-rw-r--r-- | libkdepim/categoryselectdialog.h | 8 | ||||
-rw-r--r-- | libkdepim/categoryselectdialog_base.cpp | 9 | ||||
-rw-r--r-- | libkdepim/categoryselectdialog_base.h | 1 |
4 files changed, 82 insertions, 6 deletions
diff --git a/libkdepim/categoryselectdialog.cpp b/libkdepim/categoryselectdialog.cpp index 7df9154..8b2bc4e 100644 --- a/libkdepim/categoryselectdialog.cpp +++ b/libkdepim/categoryselectdialog.cpp @@ -26,6 +26,7 @@ #include <qheader.h> #include <qapp.h> #include <qmessagebox.h> +#include <kmessagebox.h> #include "categoryeditdialog.h" @@ -41,6 +42,8 @@ CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, QWidget* parent, : CategorySelectDialog_base( parent, name, true, fl ), mPrefs( prefs ) { + mColorItem = 0; + mColorEnabled = false; mCategories->header()->hide(); setCategories(); @@ -50,6 +53,8 @@ CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, QWidget* parent, resize( 300, 360 ); else showMaximized(); + connect( mSetColorCat, SIGNAL( clicked() ), this, SLOT( setColorCat() ) ); + connect( mCategories, SIGNAL( clicked(QListViewItem *) ), this, SLOT( clicked(QListViewItem *) ) ); } void CategorySelectDialog::editCategoriesDialog() { @@ -61,11 +66,11 @@ void CategorySelectDialog::editCategoriesDialog() } void CategorySelectDialog::setCategories() { + mColorItem = 0; mCategories->clear(); mCategoryList.clear(); QStringList::Iterator it; - for (it = mPrefs->mCustomCategories.begin(); it != mPrefs->mCustomCategories.end(); ++it ) { new QCheckListItem(mCategories,*it,QCheckListItem::CheckBox); @@ -89,6 +94,8 @@ void CategorySelectDialog::setSelected(const QStringList &selList) while (item) { if (item->text() == *it) { item->setOn(true); + if ( ! found ) + setColorItem( item ); found = true; break; } @@ -113,18 +120,77 @@ QStringList CategorySelectDialog::selectedCategories() const { return mCategoryList; } +void CategorySelectDialog::setColorEnabled() +{ + mColorEnabled = true; + mSetColorCat->show(); +} +void CategorySelectDialog::setColorCat() +{ + QCheckListItem * newColorItem = (QCheckListItem * )mCategories->currentItem (); + if ( !newColorItem ) { + KMessageBox::error(this,i18n("There is no current item.")); + return; + } + if ( !newColorItem->isOn() ) + newColorItem->setOn( true ); + setColorItem( newColorItem ); +} +void CategorySelectDialog::clicked ( QListViewItem * it ) +{ + if ( ! it ) + return; + QCheckListItem *i = (QCheckListItem *) it; + qDebug("click %d ", i->isOn()); + if ( !i->isOn() && i==mColorItem) { + setColorItem( 0); + QCheckListItem *item = (QCheckListItem *)mCategories->firstChild(); + while (item) { + if (item->isOn()) { + setColorItem( item ); + break; + } + item = (QCheckListItem *)item->nextSibling(); + } + } else if ( i->isOn() && !mColorItem) { + setColorItem( i); + } +} +void CategorySelectDialog::setColorItem( QCheckListItem * newColorItem ) +{ + if ( !mColorEnabled ) + return; + if ( mColorItem == newColorItem) + return; + if ( mColorItem ) { + mColorItem->setPixmap ( 0, QPixmap() ); + mColorItem = 0; + } + if ( newColorItem ) { + QPixmap pix (newColorItem->height()/2, newColorItem->height()/2 ); + pix.fill(Qt::blue ); + newColorItem->setPixmap ( 0, pix ); + mColorItem = newColorItem; + } +} void CategorySelectDialog::slotApply() { QStringList categories; QCheckListItem *item = (QCheckListItem *)mCategories->firstChild(); + QString colcat; while (item) { if (item->isOn()) { + if ( item == mColorItem) + colcat = item->text(); + else categories.append(item->text()); } item = (QCheckListItem *)item->nextSibling(); } - + categories.sort(); + if ( ! colcat.isEmpty() ) + categories.prepend( colcat ); QString categoriesStr = categories.join(","); mCategoryList = categories; diff --git a/libkdepim/categoryselectdialog.h b/libkdepim/categoryselectdialog.h index 9b6261c..680a093 100644 --- a/libkdepim/categoryselectdialog.h +++ b/libkdepim/categoryselectdialog.h @@ -26,6 +26,7 @@ #include <categoryselectdialog_base.h> class KPimPrefs; +class QCheckListItem; namespace KPIM { @@ -39,6 +40,7 @@ class CategorySelectDialog : public CategorySelectDialog_base ~CategorySelectDialog(); void setCategories(); + void setColorEnabled(); void setSelected(const QStringList &selList); QStringList selectedCategories() const; @@ -50,15 +52,19 @@ class CategorySelectDialog : public CategorySelectDialog_base void accept(); void editCategoriesDialog(); void updateCategoryConfig(); - + void setColorCat(); + void clicked ( QListViewItem * ); signals: void categoriesSelected(const QString &); void categoriesSelected(const QStringList &); void editCategories(); private: + bool mColorEnabled; KPimPrefs *mPrefs; QStringList mCategoryList; + QCheckListItem *mColorItem; + void setColorItem( QCheckListItem * ); class CategorySelectDialogPrivate; CategorySelectDialogPrivate *d; diff --git a/libkdepim/categoryselectdialog_base.cpp b/libkdepim/categoryselectdialog_base.cpp index 3f050cf..4793fd7 100644 --- a/libkdepim/categoryselectdialog_base.cpp +++ b/libkdepim/categoryselectdialog_base.cpp @@ -36,8 +36,9 @@ CategorySelectDialog_base::CategorySelectDialog_base( QWidget* parent, const cha mCategories = new QListView( this, "mCategories" ); mCategories->addColumn( i18n( "Category" ) ); CategorySelectDialog_baseLayout->addWidget( mCategories ); - - Layout12 = new QHBoxLayout( 0, 0, 6, "Layout12"); + mSetColorCat = new QPushButton( this, "msetColor" ); + CategorySelectDialog_baseLayout->addWidget( mSetColorCat ); + Layout12 = new QHBoxLayout( 0, 0, 4, "Layout12"); mClear = new QPushButton( this, "mClear" ); Layout12->addWidget( mClear ); @@ -48,7 +49,7 @@ CategorySelectDialog_base::CategorySelectDialog_base( QWidget* parent, const cha Layout12->addWidget( mButtonEdit ); CategorySelectDialog_baseLayout->addLayout( Layout12 ); - Layout11 = new QHBoxLayout( 0, 0, 6, "Layout11"); + Layout11 = new QHBoxLayout( 0, 0, 4, "Layout11"); //mButtonHelp = new QPushButton( this, "mButtonHelp" ); //Layout11->addWidget( mButtonHelp ); @@ -84,6 +85,7 @@ CategorySelectDialog_base::CategorySelectDialog_base( QWidget* parent, const cha setTabOrder( mButtonOk, mButtonCancel ); // showMaximized(); //raise(); + mSetColorCat->hide(); } /* @@ -107,6 +109,7 @@ void CategorySelectDialog_base::languageChange() // mButtonHelp->setText( tr2i18n( "&Help" ) ); //mApply->setText( i18n( "&Apply" ) ); mButtonOk->setText( i18n( "&OK" ) ); + mSetColorCat->setText( i18n( "Set current as color category" ) ); mButtonCancel->setText( i18n( "&Cancel" ) ); } diff --git a/libkdepim/categoryselectdialog_base.h b/libkdepim/categoryselectdialog_base.h index af905ed..59ffa22 100644 --- a/libkdepim/categoryselectdialog_base.h +++ b/libkdepim/categoryselectdialog_base.h @@ -35,6 +35,7 @@ public: QPushButton* mApply; QPushButton* mButtonOk; QPushButton* mButtonCancel; + QPushButton* mSetColorCat; public slots: virtual void clear(); |