Diffstat (limited to 'korganizer/koeditorgeneral.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeditorgeneral.cpp | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/korganizer/koeditorgeneral.cpp b/korganizer/koeditorgeneral.cpp index 915c7ec..50a04ea 100644 --- a/korganizer/koeditorgeneral.cpp +++ b/korganizer/koeditorgeneral.cpp @@ -141,19 +141,58 @@ void KOEditorGeneral::editCategories() csd->setSelected( QStringList::split (",", mCategoriesLabel->text()) ); csd->exec(); delete csd; } + +void KOEditorGeneral::showCatPopup() +{ + mCatPopup->clear(); + QStringList checkedCategories = QStringList::split (",", mCategoriesLabel->text()); + int index = 0; + for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); + it != KOPrefs::instance()->mCustomCategories.end (); + ++it) { + mCatPopup->insertItem (*it, index ); + //mCategory[index] = *it; + if (checkedCategories.find (*it) != checkedCategories.end ()) mCatPopup->setItemChecked (index, true); + ++index; + } +} +void KOEditorGeneral::selectedCatPopup( int index ) +{ + qDebug("i %d c %d ", index, KOPrefs::instance()->mCustomCategories.count()); + QStringList categories = QStringList::split (",", mCategoriesLabel->text()); + QString colcat = categories.first(); + if (categories.find (KOPrefs::instance()->mCustomCategories[index]) != categories.end ()) + categories.remove (KOPrefs::instance()->mCustomCategories[index]); + else + categories.insert (categories.end(), KOPrefs::instance()->mCustomCategories[index]); + categories.sort (); + if ( !colcat.isEmpty() ) { + if ( categories.find ( colcat ) != categories.end () ) { + categories.remove( colcat ); + categories.prepend( colcat ); + } + } + mCategoriesLabel->setText( categories.join(",") ); +} + void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout) { QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout ); - + mCatPopup = new QPopupMenu ( parent ); + mCatPopup->setCheckable (true); + connect(mCatPopup,SIGNAL(aboutToShow () ), this ,SLOT(showCatPopup())); + connect(mCatPopup,SIGNAL( activated ( int ) ), this ,SLOT(selectedCatPopup( int ))); mCategoriesButton = new QPushButton(parent); - mCategoriesButton->setText(i18n("Categories...")); - connect(mCategoriesButton,SIGNAL(clicked()),this, SLOT(editCategories() )); + mCategoriesButton->setText(i18n("Categories")); + //connect(mCategoriesButton,SIGNAL(clicked()),this, SLOT(editCategories() )); categoriesLayout->addWidget(mCategoriesButton); - - mCategoriesLabel = new QLabel(parent); - mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken); + mCategoriesButton->setPopup( mCatPopup ); + mCategoriesLabel = new QPushButton(parent);//new QLabel(parent); + mCategoriesLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) ); + connect(mCategoriesLabel,SIGNAL(clicked()),this, SLOT(editCategories() )); + //mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken); categoriesLayout->addWidget(mCategoriesLabel,1); } void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout) |