21 #include "kscoringeditor.h"
24 #include <tdelocale.h>
25 #include <kcombobox.h>
26 #include <kcolorcombo.h>
27 #include <kiconloader.h>
28 #include <kregexpeditorinterface.h>
30 #include <tdeparts/componentfactory.h>
34 #include <tqpushbutton.h>
36 #include <tqtooltip.h>
37 #include <tqcheckbox.h>
38 #include <tqbuttongroup.h>
39 #include <tqradiobutton.h>
40 #include <tqwidgetstack.h>
41 #include <tqapplication.h>
46 template <
class T>
static int setCurrentItem(T *box,
const TQString& s)
48 int cnt = box->count();
49 for (
int i=0;i<cnt;++i) {
50 if (box->text(i) == s) {
51 box->setCurrentItem(i);
64 SingleConditionWidget::SingleConditionWidget(KScoringManager *m,TQWidget *p,
const char *n)
65 : TQFrame(p,n), manager(m)
67 TQBoxLayout *topL =
new TQVBoxLayout(
this,5);
68 TQBoxLayout *firstRow =
new TQHBoxLayout(topL);
69 neg =
new TQCheckBox(i18n(
"Not"),
this);
70 TQToolTip::add(neg,i18n(
"Negate this condition"));
71 firstRow->addWidget(neg);
72 headers =
new KComboBox(
this);
73 headers->insertStringList(manager->getDefaultHeaders());
74 headers->setEditable(
true );
75 TQToolTip::add(headers,i18n(
"Select the header to match this condition against"));
76 firstRow->addWidget(headers,1);
77 matches =
new KComboBox(
this);
78 matches->insertStringList(KScoringExpression::conditionNames());
79 TQToolTip::add(matches,i18n(
"Select the type of match"));
80 firstRow->addWidget(matches,1);
81 connect( matches, TQT_SIGNAL( activated(
int ) ), TQT_SLOT( toggleRegExpButton(
int ) ) );
82 TQHBoxLayout *secondRow =
new TQHBoxLayout( topL );
83 secondRow->setSpacing( 1 );
84 expr =
new KLineEdit(
this );
85 TQToolTip::add(expr,i18n(
"The condition for the match"));
87 expr->setMinimumWidth(fontMetrics().maxWidth()*20);
88 secondRow->addWidget( expr );
89 regExpButton =
new TQPushButton( i18n(
"Edit..."),
this );
90 secondRow->addWidget( regExpButton );
91 connect( regExpButton, TQT_SIGNAL( clicked() ), TQT_SLOT( showRegExpDialog() ) );
94 setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed));
95 setFrameStyle(Box | Sunken);
99 SingleConditionWidget::~SingleConditionWidget()
102 void SingleConditionWidget::setCondition(KScoringExpression *e)
104 neg->setChecked(e->isNeg());
105 headers->setCurrentText( e->getHeader() );
106 setCurrentItem(matches,KScoringExpression::getNameForCondition(e->getCondition()));
107 toggleRegExpButton( matches->currentItem() );
108 expr->setText(e->getExpression());
111 KScoringExpression* SingleConditionWidget::createCondition()
const
113 TQString head = headers->currentText();
114 TQString match = matches->currentText();
115 int condType = KScoringExpression::getConditionForName(match);
116 match = KScoringExpression::getTypeString(condType);
117 TQString cond = expr->text();
118 TQString negs = (neg->isChecked())?
"1":
"0";
119 return new KScoringExpression(head,match,cond,negs);
122 void SingleConditionWidget::clear()
124 neg->setChecked(
false);
128 void SingleConditionWidget::toggleRegExpButton(
int selected )
130 bool isRegExp = (KScoringExpression::MATCH == selected ||
131 KScoringExpression::MATCHCS == selected) &&
132 !TDETrader::self()->query(
"KRegExpEditor/KRegExpEditor").isEmpty();
133 regExpButton->setEnabled( isRegExp );
136 void SingleConditionWidget::showRegExpDialog()
138 TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>(
"KRegExpEditor/KRegExpEditor" );
139 if ( editorDialog ) {
140 KRegExpEditorInterface *editor =
static_cast<KRegExpEditorInterface *
>( editorDialog->tqt_cast(
"KRegExpEditorInterface" ) );
142 editor->setRegExp( expr->text() );
143 editorDialog->exec();
144 expr->setText( editor->regExp() );
153 ConditionEditWidget::ConditionEditWidget(KScoringManager *m, TQWidget *p,
const char *n)
160 ConditionEditWidget::~ConditionEditWidget()
170 Q_ASSERT( w->isA(
"SingleConditionWidget") );
176 void ConditionEditWidget::slotEditRule(KScoringRule *rule)
178 KScoringRule::ScoreExprList l;
179 if (rule) l = rule->getExpressions();
180 if (!rule || l.count() == 0) {
184 KScoringExpression *e = l.first();
187 scw->setCondition(e);
194 void ConditionEditWidget::updateRule(KScoringRule *rule)
196 rule->cleanExpressions();
198 if (! w->isA(
"SingleConditionWidget")) {
199 kdWarning(5100) <<
"there is a widget in ConditionEditWidget "
200 <<
"which isn't a SingleConditionWidget" << endl;
204 rule->addExpression(saw->createCondition());
214 SingleActionWidget::SingleActionWidget(KScoringManager *m,TQWidget *p,
const char *n)
215 : TQWidget(p,n), notifyEditor(0), scoreEditor(0), colorEditor(0),manager(m)
217 TQHBoxLayout *topL =
new TQHBoxLayout(
this,0,5);
218 types =
new KComboBox(
this);
219 types->setEditable(
false);
220 topL->addWidget(types);
221 stack =
new TQWidgetStack(
this);
222 topL->addWidget(stack);
224 dummyLabel =
new TQLabel(i18n(
"Select an action."), stack);
225 stack->addWidget(dummyLabel, 0);
229 types->insertItem(TQString());
230 TQStringList l = ActionBase::userNames();
231 for ( TQStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
233 int feature = ActionBase::getTypeForUserName(name);
234 if (manager->hasFeature(feature)) {
235 types->insertItem(name);
238 case ActionBase::SETSCORE:
239 w = scoreEditor =
new KIntSpinBox(-99999,99999,1,0,10, stack);
241 case ActionBase::NOTIFY:
242 w = notifyEditor =
new KLineEdit(stack);
244 case ActionBase::COLOR:
245 w = colorEditor =
new KColorCombo(stack);
247 case ActionBase::MARKASREAD:
248 w =
new TQLabel( stack );
252 stack->addWidget(w,index++);
256 connect(types,TQT_SIGNAL(activated(
int)),stack,TQT_SLOT(raiseWidget(
int)));
259 types->setCurrentItem(0);
260 stack->raiseWidget(dummyLabel);
263 SingleActionWidget::~SingleActionWidget()
267 void SingleActionWidget::setAction(
ActionBase *act)
269 kdDebug(5100) <<
"SingleActionWidget::setAction()" << endl;
270 setCurrentItem(types,ActionBase::userName(act->getType()));
271 int index = types->currentItem();
272 stack->raiseWidget(index);
273 switch (act->getType()) {
274 case ActionBase::SETSCORE:
275 scoreEditor->setValue(act->getValueString().toInt());
277 case ActionBase::NOTIFY:
278 notifyEditor->setText(act->getValueString());
280 case ActionBase::COLOR:
281 colorEditor->setColor(TQColor(act->getValueString()));
283 case ActionBase::MARKASREAD:
287 kdWarning(5100) <<
"unknown action type in SingleActionWidget::setAction()" << endl;
291 ActionBase* SingleActionWidget::createAction()
const
294 if (types->currentText().isEmpty())
297 int type = ActionBase::getTypeForUserName(types->currentText());
299 case ActionBase::SETSCORE:
300 return new ActionSetScore(scoreEditor->value());
301 case ActionBase::NOTIFY:
302 return new ActionNotify(notifyEditor->text());
303 case ActionBase::COLOR:
304 return new ActionColor(TQString(colorEditor->color().name()));
305 case ActionBase::MARKASREAD:
306 return new ActionMarkAsRead();
308 kdWarning(5100) <<
"unknown action type in SingleActionWidget::getValue()" << endl;
313 void SingleActionWidget::clear()
315 if (scoreEditor) scoreEditor->setValue(0);
316 if (notifyEditor) notifyEditor->clear();
317 if (colorEditor) colorEditor->setCurrentItem(0);
318 types->setCurrentItem(0);
319 stack->raiseWidget(dummyLabel);
327 ActionEditWidget::ActionEditWidget(KScoringManager *m,TQWidget *p,
const char *n)
334 ActionEditWidget::~ActionEditWidget()
342 void ActionEditWidget::slotEditRule(KScoringRule *rule)
344 KScoringRule::ActionList l;
345 if (rule) l = rule->getActions();
346 if (!rule || l.count() == 0) {
360 void ActionEditWidget::updateRule(KScoringRule *rule)
362 rule->cleanActions();
364 if (! w->isA(
"SingleActionWidget")) {
365 kdWarning(5100) <<
"there is a widget in ActionEditWidget "
366 <<
"which isn't a SingleActionWidget" << endl;
373 rule->addAction(act);
381 Q_ASSERT( w->isA(
"SingleActionWidget") );
392 RuleEditWidget::RuleEditWidget(KScoringManager *m,TQWidget *p,
const char *n)
393 : TQWidget(p,n), dirty(false), manager(m), oldRuleName(TQString())
395 kdDebug(5100) <<
"RuleEditWidget::RuleEditWidget()" << endl;
396 if ( !n ) setName(
"RuleEditWidget" );
397 TQVBoxLayout *topLayout =
new TQVBoxLayout(
this, 5, KDialog::spacingHint() );
400 TQGroupBox *groupB =
new TQGroupBox(i18n(
"Properties"),
this);
401 topLayout->addWidget(groupB);
402 TQGridLayout* groupL =
new TQGridLayout(groupB, 6,2, 8,5);
403 groupL->addRowSpacing(0, fontMetrics().lineSpacing()-4);
406 ruleNameEdit =
new KLineEdit( groupB,
"ruleNameEdit" );
407 groupL->addWidget( ruleNameEdit, 1, 1 );
408 TQLabel *ruleNameLabel =
new TQLabel(ruleNameEdit, i18n(
"&Name:"), groupB,
"ruleNameLabel");
409 groupL->addWidget( ruleNameLabel, 1, 0 );
412 groupsEdit =
new KLineEdit( groupB,
"groupsEdit" );
413 groupL->addWidget( groupsEdit, 2, 1 );
414 TQLabel *groupsLabel =
new TQLabel(groupsEdit, i18n(
"&Groups:"), groupB,
"groupsLabel");
415 groupL->addWidget( groupsLabel, 2, 0 );
417 TQPushButton *groupsBtn =
new TQPushButton(i18n(
"A&dd Group"), groupB);
418 connect(groupsBtn,TQT_SIGNAL(clicked()),TQT_SLOT(slotAddGroup()));
419 groupL->addWidget( groupsBtn, 3, 0 );
421 groupsBox =
new KComboBox(
false, groupB,
"groupsBox" );
422 groupsBox->setDuplicatesEnabled(
false);
423 groupsBox->insertStringList(manager->getGroups());
424 groupsBox->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
425 groupL->addWidget( groupsBox, 3, 1 );
428 expireCheck =
new TQCheckBox(i18n(
"&Expire rule automatically"), groupB);
429 groupL->addMultiCellWidget( expireCheck, 4,4, 0,1 );
430 expireEdit =
new KIntSpinBox(1,99999,1,30,10, groupB,
"expireWidget");
432 slotExpireEditChanged(30);
433 connect(expireEdit, TQT_SIGNAL(valueChanged(
int)), TQT_SLOT(slotExpireEditChanged(
int)));
434 groupL->addWidget( expireEdit, 5, 1 );
435 expireLabel =
new TQLabel(expireEdit, i18n(
"&Rule is valid for:"), groupB,
"expireLabel");
436 groupL->addWidget( expireLabel, 5, 0 );
437 expireLabel->setEnabled(
false);
438 expireEdit->setEnabled(
false);
440 connect(expireCheck, TQT_SIGNAL(toggled(
bool)), expireLabel, TQT_SLOT(setEnabled(
bool)));
441 connect(expireCheck, TQT_SIGNAL(toggled(
bool)), expireEdit, TQT_SLOT(setEnabled(
bool)));
444 TQGroupBox *groupConds =
new TQGroupBox(i18n(
"Conditions"),
this);
445 topLayout->addWidget(groupConds);
446 TQGridLayout *condL =
new TQGridLayout(groupConds, 3,2, 8,5);
448 condL->addRowSpacing(0, fontMetrics().lineSpacing()-4);
450 TQButtonGroup *buttonGroup =
new TQButtonGroup(groupConds);
452 linkModeAnd =
new TQRadioButton(i18n(
"Match a&ll conditions"), groupConds);
453 buttonGroup->insert(linkModeAnd);
454 condL->addWidget(linkModeAnd, 1,0);
455 linkModeOr =
new TQRadioButton(i18n(
"Matc&h any condition"), groupConds);
456 buttonGroup->insert(linkModeOr);
457 condL->addWidget(linkModeOr, 1,1);
458 linkModeAnd->setChecked(
true);
461 condL->addMultiCellWidget(condEditor, 2,2, 0,1);
462 connect(condEditor,TQT_SIGNAL(
widgetRemoved()),
this,TQT_SLOT(slotShrink()));
465 TQGroupBox *groupActions =
new TQGroupBox(i18n(
"Actions"),
this);
466 topLayout->addWidget(groupActions);
467 TQBoxLayout *actionL =
new TQVBoxLayout(groupActions,8,5);
468 actionL->addSpacing(fontMetrics().lineSpacing()-4);
470 actionL->addWidget(actionEditor);
471 connect(actionEditor,TQT_SIGNAL(
widgetRemoved()),
this,TQT_SLOT(slotShrink()));
473 topLayout->addStretch(1);
475 kdDebug(5100) <<
"constructed RuleEditWidget" << endl;
478 RuleEditWidget::~RuleEditWidget()
482 void RuleEditWidget::slotEditRule(
const TQString& ruleName)
484 kdDebug(5100) <<
"RuleEditWidget::slotEditRule(" << ruleName <<
")" << endl;
496 KScoringRule* rule = manager->findRule(ruleName);
498 kdDebug(5100) <<
"no rule for ruleName " << ruleName << endl;
502 oldRuleName = rule->getName();
503 ruleNameEdit->setText(rule->getName());
504 groupsEdit->setText(rule->getGroups().join(
";"));
506 bool b = rule->getExpireDate().isValid();
507 expireCheck->setChecked(b);
508 expireEdit->setEnabled(b);
509 expireLabel->setEnabled(b);
511 expireEdit->setValue(TQDate::currentDate().daysTo(rule->getExpireDate()));
513 expireEdit->setValue(30);
514 if (rule->getLinkMode() == KScoringRule::AND) {
515 linkModeAnd->setChecked(
true);
518 linkModeOr->setChecked(
true);
521 condEditor->slotEditRule(rule);
522 actionEditor->slotEditRule(rule);
524 kdDebug(5100) <<
"RuleEditWidget::slotEditRule() ready" << endl;
527 void RuleEditWidget::clearContents()
529 ruleNameEdit->setText(
"");
530 groupsEdit->setText(
"");
531 expireCheck->setChecked(
false);
532 expireEdit->setValue(30);
533 expireEdit->setEnabled(
false);
534 condEditor->slotEditRule(0);
535 actionEditor->slotEditRule(0);
536 oldRuleName = TQString();
539 void RuleEditWidget::updateRule(KScoringRule *rule)
541 oldRuleName = TQString();
542 TQString groups = groupsEdit->text();
543 if (groups.isEmpty())
544 rule->setGroups(TQStringList(
".*"));
546 rule->setGroups(TQStringList::split(
";",groups));
547 bool b = expireCheck->isChecked();
549 rule->setExpireDate(TQDate::currentDate().addDays(expireEdit->value()));
551 rule->setExpireDate(TQDate());
552 actionEditor->updateRule(rule);
553 rule->setLinkMode(linkModeAnd->isChecked()?KScoringRule::AND:KScoringRule::OR);
554 condEditor->updateRule(rule);
555 if (rule->getName() != ruleNameEdit->text())
556 manager->setRuleName(rule,ruleNameEdit->text());
559 void RuleEditWidget::updateRule()
561 KScoringRule *rule = manager->findRule(oldRuleName);
562 if (rule) updateRule(rule);
565 void RuleEditWidget::slotAddGroup()
567 TQString grp = groupsBox->currentText();
570 TQString txt = groupsEdit->text().stripWhiteSpace();
571 if ( txt ==
".*" || txt.isEmpty() ) groupsEdit->setText(grp);
572 else groupsEdit->setText(txt +
";" + grp);
575 void RuleEditWidget::setDirty()
577 kdDebug(5100) <<
"RuleEditWidget::setDirty()" << endl;
582 void RuleEditWidget::slotShrink()
587 void RuleEditWidget::slotExpireEditChanged(
int value)
589 expireEdit->setSuffix(i18n(
" day",
" days", value));
597 RuleListWidget::RuleListWidget(KScoringManager *m,
bool standalone, TQWidget *p,
const char *n)
598 : TQWidget(p,n), alone(standalone), manager(m)
600 kdDebug(5100) <<
"RuleListWidget::RuleListWidget()" << endl;
601 if (!n) setName(
"RuleListWidget");
602 TQVBoxLayout *topL =
new TQVBoxLayout(
this,standalone? 0:5,KDialog::spacingHint());
603 ruleList =
new TDEListBox(
this);
605 connect(ruleList,TQT_SIGNAL(doubleClicked(TQListBoxItem*)),
606 this,TQT_SLOT(slotEditRule(TQListBoxItem*)));
607 connect(ruleList,TQT_SIGNAL(returnPressed(TQListBoxItem*)),
608 this,TQT_SLOT(slotEditRule(TQListBoxItem*)));
610 connect(ruleList, TQT_SIGNAL(currentChanged(TQListBoxItem*)),
611 this, TQT_SLOT(slotRuleSelected(TQListBoxItem*)));
612 topL->addWidget(ruleList);
614 TQHBoxLayout *btnL =
new TQHBoxLayout( topL, KDialog::spacingHint() );
615 mRuleUp =
new TQPushButton(
this );
616 mRuleUp->setPixmap( BarIcon(
"go-up", TDEIcon::SizeSmall ) );
617 TQToolTip::add( mRuleUp, i18n(
"Move rule up") );
618 btnL->addWidget( mRuleUp );
619 connect( mRuleUp, TQT_SIGNAL( clicked() ), TQT_SLOT( slotRuleUp() ) );
620 mRuleDown =
new TQPushButton(
this );
621 mRuleDown->setPixmap( BarIcon(
"go-down", TDEIcon::SizeSmall ) );
622 TQToolTip::add( mRuleDown, i18n(
"Move rule down") );
623 btnL->addWidget( mRuleDown );
624 connect( mRuleDown, TQT_SIGNAL( clicked() ), TQT_SLOT( slotRuleDown() ) );
626 btnL =
new TQHBoxLayout( topL, KDialog::spacingHint() );
628 newRule =
new TQPushButton(
this);
629 newRule->setPixmap( BarIcon(
"document-new", TDEIcon::SizeSmall ) );
630 TQToolTip::add(newRule,i18n(
"New rule")),
631 btnL->addWidget(newRule);
632 connect(newRule, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotNewRule()));
635 editRule =
new TQPushButton(
this);
636 editRule->setIconSet( BarIconSet(
"edit", TDEIcon::SizeSmall) );
637 TQToolTip::add(editRule,i18n(
"Edit rule"));
638 btnL->addWidget(editRule);
639 connect(editRule,TQT_SIGNAL(clicked()),
this,TQT_SLOT(slotEditRule()));
641 delRule =
new TQPushButton(
this);
642 delRule->setIconSet( BarIconSet(
"edit-delete", TDEIcon::SizeSmall ) );
643 TQToolTip::add(delRule,i18n(
"Remove rule"));
644 btnL->addWidget(delRule);
645 connect(delRule, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotDelRule()));
646 copyRule =
new TQPushButton(
this);
647 copyRule->setIconSet(BarIconSet(
"edit-copy", TDEIcon::SizeSmall));
648 TQToolTip::add(copyRule,i18n(
"Copy rule"));
649 btnL->addWidget(copyRule);
650 connect(copyRule, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotCopyRule()));
653 TQBoxLayout *filterL =
new TQVBoxLayout(topL,KDialog::spacingHint());
654 KComboBox *filterBox =
new KComboBox(
this);
655 TQStringList l = m->getGroups();
656 filterBox->insertItem(i18n(
"<all groups>"));
657 filterBox->insertStringList(l);
658 filterBox->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
659 connect(filterBox,TQT_SIGNAL(activated(
const TQString&)),
660 this,TQT_SLOT(slotGroupFilter(
const TQString&)));
661 slotGroupFilter(i18n(
"<all groups>"));
662 TQLabel *lab =
new TQLabel(filterBox,i18n(
"Sho&w only rules for group:"),
this);
663 filterL->addWidget(lab);
664 filterL->addWidget(filterBox);
666 connect(manager,TQT_SIGNAL(changedRules()),
667 this,TQT_SLOT(updateRuleList()));
668 connect(manager,TQT_SIGNAL(changedRuleName(
const TQString&,
const TQString&)),
669 this,TQT_SLOT(slotRuleNameChanged(
const TQString&,
const TQString&)));
675 RuleListWidget::~RuleListWidget()
679 void RuleListWidget::updateButton()
681 bool state = ruleList->count() > 0;
683 editRule->setEnabled(state);
684 delRule->setEnabled(state);
685 copyRule->setEnabled(state);
687 TQListBoxItem *item = ruleList->item( ruleList->currentItem() );
689 mRuleUp->setEnabled( item->prev() != 0 );
690 mRuleDown->setEnabled( item->next() != 0 );
694 void RuleListWidget::updateRuleList()
697 kdDebug(5100) <<
"RuleListWidget::updateRuleList()" << endl;
698 TQString curr = ruleList->currentText();
700 if (group == i18n(
"<all groups>")) {
701 TQStringList l = manager->getRuleNames();
702 ruleList->insertStringList(l);
704 KScoringManager::ScoringRuleList l = manager->getAllRules();
705 for (KScoringRule* rule = l.first(); rule; rule = l.next() ) {
706 if (rule->matchGroup(group)) ruleList->insertItem(rule->getName());
709 int index = setCurrentItem(ruleList,curr);
711 ruleList->setCurrentItem(0);
712 slotRuleSelected(ruleList->currentText());
715 slotRuleSelected(curr);
719 void RuleListWidget::updateRuleList(
const KScoringRule *rule)
721 kdDebug(5100) <<
"RuleListWidget::updateRuleList(" << rule->getName() <<
")" << endl;
722 TQString name = rule->getName();
724 slotRuleSelected(name);
727 void RuleListWidget::slotRuleNameChanged(
const TQString& oldName,
const TQString& newName)
729 int ind = ruleList->currentItem();
730 for (uint i=0;i<ruleList->count();++i)
731 if (ruleList->text(i) == oldName) {
732 ruleList->changeItem(newName,i);
733 ruleList->setCurrentItem(ind);
738 void RuleListWidget::slotEditRule(
const TQString& s)
743 void RuleListWidget::slotEditRule()
745 if (ruleList->currentItem() >= 0) {
746 emit ruleEdited(ruleList->currentText());
748 else if (ruleList->count() == 0)
749 emit ruleEdited(TQString());
752 void RuleListWidget::slotEditRule(TQListBoxItem* item)
754 slotEditRule(item->text());
757 void RuleListWidget::slotGroupFilter(
const TQString& s)
763 void RuleListWidget::slotRuleSelected(
const TQString& ruleName)
766 kdDebug(5100) <<
"RuleListWidget::slotRuleSelected(" << ruleName <<
")" << endl;
767 if (ruleName != ruleList->currentText()) {
768 setCurrentItem(ruleList,ruleName);
771 emit ruleSelected(ruleName);
774 void RuleListWidget::slotRuleSelected(TQListBoxItem *item)
777 TQString ruleName = item->text();
778 slotRuleSelected(ruleName);
781 void RuleListWidget::slotRuleSelected(
int index)
784 if (idx >= ruleList->count())
return;
785 TQString ruleName = ruleList->text(index);
786 slotRuleSelected(ruleName);
789 void RuleListWidget::slotNewRule()
792 KScoringRule *rule = manager->addRule();
793 updateRuleList(rule);
794 if (alone) slotEditRule(rule->getName());
798 void RuleListWidget::slotDelRule()
800 KScoringRule *rule = manager->findRule(ruleList->currentText());
802 manager->deleteRule(rule);
804 if (!alone) slotEditRule();
808 void RuleListWidget::slotCopyRule()
811 TQString ruleName = ruleList->currentText();
812 KScoringRule *rule = manager->findRule(ruleName);
814 KScoringRule *nrule = manager->copyRule(rule);
815 updateRuleList(nrule);
816 slotEditRule(nrule->getName());
821 void RuleListWidget::slotRuleUp()
823 KScoringRule *rule = 0, *below = 0;
824 TQListBoxItem *item = ruleList->item( ruleList->currentItem() );
826 rule = manager->findRule( item->text() );
829 below = manager->findRule( item->text() );
832 manager->moveRuleAbove( rule, below );
837 void RuleListWidget::slotRuleDown()
839 KScoringRule *rule = 0, *above = 0;
840 TQListBoxItem *item = ruleList->item( ruleList->currentItem() );
842 rule = manager->findRule( item->text() );
845 above = manager->findRule( item->text() );
848 manager->moveRuleBelow( rule, above );
858 KScoringEditor* KScoringEditor::scoreEditor = 0;
860 KScoringEditor::KScoringEditor(KScoringManager* m,
861 TQWidget *parent,
const char *name)
862 : KDialogBase(parent,name,false,i18n(
"Rule Editor"),Ok|Apply|Cancel,Ok,true), manager(m)
864 manager->pushRuleList();
865 if (!scoreEditor) scoreEditor =
this;
866 kdDebug(5100) <<
"KScoringEditor::KScoringEditor()" << endl;
867 if (!name) setName(
"KScoringEditor");
870 TQWidget *w =
new TQWidget(
this);
872 TQHBoxLayout *hbl =
new TQHBoxLayout(w,0,spacingHint());
874 hbl->addWidget(ruleLister);
876 hbl->addWidget(ruleEditor);
877 connect(ruleLister,TQT_SIGNAL(ruleSelected(
const TQString&)),
878 ruleEditor, TQT_SLOT(slotEditRule(
const TQString&)));
879 connect(ruleLister, TQT_SIGNAL(leavingRule()),
880 ruleEditor, TQT_SLOT(updateRule()));
881 connect(ruleEditor, TQT_SIGNAL(shrink()), TQT_SLOT(slotShrink()));
882 connect(
this,TQT_SIGNAL(finished()),TQT_SLOT(slotFinished()));
883 ruleLister->slotRuleSelected(0);
884 resize(550, sizeHint().height());
887 void KScoringEditor::setDirty()
889 TQPushButton *applyBtn = actionButton(Apply);
890 applyBtn->setEnabled(
true);
893 KScoringEditor::~KScoringEditor()
898 KScoringEditor* KScoringEditor::createEditor(KScoringManager* m,
899 TQWidget *parent,
const char *name)
901 if (scoreEditor)
return scoreEditor;
902 else return new KScoringEditor(m,parent,name);
905 void KScoringEditor::setRule(KScoringRule* r)
907 kdDebug(5100) <<
"KScoringEditor::setRule(" << r->getName() <<
")" << endl;
908 TQString ruleName = r->getName();
909 ruleLister->slotRuleSelected(ruleName);
912 void KScoringEditor::slotShrink()
914 TQTimer::singleShot(5,
this, TQT_SLOT(slotDoShrink()));
917 void KScoringEditor::slotDoShrink()
920 TQApplication::sendPostedEvents();
921 resize(width(),sizeHint().height());
924 void KScoringEditor::slotApply()
926 TQString ruleName = ruleLister->currentRule();
927 KScoringRule *rule = manager->findRule(ruleName);
929 ruleEditor->updateRule(rule);
930 ruleLister->updateRuleList(rule);
932 manager->removeTOS();
933 manager->pushRuleList();
936 void KScoringEditor::slotOk()
939 manager->removeTOS();
940 KDialogBase::slotOk();
941 manager->editorReady();
944 void KScoringEditor::slotCancel()
946 manager->popRuleList();
947 KDialogBase::slotCancel();
950 void KScoringEditor::slotFinished()
960 KScoringEditorWidgetDialog::KScoringEditorWidgetDialog(KScoringManager *m,
const TQString& r, TQWidget *p,
const char *n)
961 : KDialogBase(p,n,true,i18n(
"Edit Rule"),
962 KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Close,
963 KDialogBase::Ok,true),
964 manager(m), ruleName(r)
966 TQFrame *f = makeMainWidget();
967 TQBoxLayout *topL =
new TQVBoxLayout(f);
969 connect(ruleEditor, TQT_SIGNAL(shrink()), TQT_SLOT(slotShrink()));
970 topL->addWidget(ruleEditor);
971 ruleEditor->slotEditRule(ruleName);
975 void KScoringEditorWidgetDialog::slotApply()
977 KScoringRule *rule = manager->findRule(ruleName);
979 ruleEditor->updateRule(rule);
980 ruleName = rule->getName();
984 void KScoringEditorWidgetDialog::slotOk()
987 KDialogBase::slotOk();
990 void KScoringEditorWidgetDialog::slotShrink()
992 TQTimer::singleShot(5,
this, TQT_SLOT(slotDoShrink()));
995 void KScoringEditorWidgetDialog::slotDoShrink()
998 TQApplication::sendPostedEvents();
999 resize(width(),sizeHint().height());
1007 KScoringEditorWidget::KScoringEditorWidget(KScoringManager *m,TQWidget *p,
const char *n)
1008 : TQWidget(p,n), manager(m)
1010 TQBoxLayout *topL =
new TQVBoxLayout(
this);
1012 topL->addWidget(ruleLister);
1013 connect(ruleLister,TQT_SIGNAL(ruleEdited(
const TQString&)),
1014 this,TQT_SLOT(slotRuleEdited(
const TQString &)));
1017 KScoringEditorWidget::~KScoringEditorWidget()
1019 manager->editorReady();
1022 void KScoringEditorWidget::slotRuleEdited(
const TQString& ruleName)
1024 KScoringEditorWidgetDialog dlg(manager,ruleName,
this);
1026 ruleLister->updateRuleList();
1029 #include "kscoringeditor.moc"