19 #include "kscoringeditor.h"
22 #include <tdelocale.h>
23 #include <kcombobox.h>
24 #include <kcolorcombo.h>
25 #include <kiconloader.h>
26 #include <kregexpeditorinterface.h>
28 #include <tdeparts/componentfactory.h>
32 #include <tqpushbutton.h>
34 #include <tqtooltip.h>
35 #include <tqcheckbox.h>
36 #include <tqbuttongroup.h>
37 #include <tqradiobutton.h>
38 #include <tqwidgetstack.h>
39 #include <tqapplication.h>
44 template <
class T>
static int setCurrentItem(T *box,
const TQString& s)
46 int cnt = box->count();
47 for (
int i=0;i<cnt;++i) {
48 if (box->text(i) == s) {
49 box->setCurrentItem(i);
62 SingleConditionWidget::SingleConditionWidget(KScoringManager *m,TQWidget *p,
const char *n)
63 : TQFrame(p,n), manager(m)
65 TQBoxLayout *topL =
new TQVBoxLayout(
this,5);
66 TQBoxLayout *firstRow =
new TQHBoxLayout(topL);
67 neg =
new TQCheckBox(i18n(
"Not"),
this);
68 TQToolTip::add(neg,i18n(
"Negate this condition"));
69 firstRow->addWidget(neg);
70 headers =
new KComboBox(
this);
71 headers->insertStringList(manager->getDefaultHeaders());
72 headers->setEditable(
true );
73 TQToolTip::add(headers,i18n(
"Select the header to match this condition against"));
74 firstRow->addWidget(headers,1);
75 matches =
new KComboBox(
this);
76 matches->insertStringList(KScoringExpression::conditionNames());
77 TQToolTip::add(matches,i18n(
"Select the type of match"));
78 firstRow->addWidget(matches,1);
79 connect( matches, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( toggleRegExpButton(
int ) ) );
80 TQHBoxLayout *secondRow =
new TQHBoxLayout( topL );
81 secondRow->setSpacing( 1 );
82 expr =
new KLineEdit(
this );
83 TQToolTip::add(expr,i18n(
"The condition for the match"));
85 expr->setMinimumWidth(fontMetrics().maxWidth()*20);
86 secondRow->addWidget( expr );
87 regExpButton =
new TQPushButton( i18n(
"Edit..."),
this );
88 secondRow->addWidget( regExpButton );
89 connect( regExpButton, TQ_SIGNAL( clicked() ), TQ_SLOT( showRegExpDialog() ) );
92 setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed));
93 setFrameStyle(Box | Sunken);
97 SingleConditionWidget::~SingleConditionWidget()
100 void SingleConditionWidget::setCondition(KScoringExpression *e)
102 neg->setChecked(e->isNeg());
103 headers->setCurrentText( e->getHeader() );
104 setCurrentItem(matches,KScoringExpression::getNameForCondition(e->getCondition()));
105 toggleRegExpButton( matches->currentItem() );
106 expr->setText(e->getExpression());
109 KScoringExpression* SingleConditionWidget::createCondition()
const
111 TQString head = headers->currentText();
112 TQString match = matches->currentText();
113 int condType = KScoringExpression::getConditionForName(match);
114 match = KScoringExpression::getTypeString(condType);
115 TQString cond = expr->text();
116 TQString negs = (neg->isChecked())?
"1":
"0";
117 return new KScoringExpression(head,match,cond,negs);
120 void SingleConditionWidget::clear()
122 neg->setChecked(
false);
126 void SingleConditionWidget::toggleRegExpButton(
int selected )
128 bool isRegExp = (KScoringExpression::MATCH == selected ||
129 KScoringExpression::MATCHCS == selected) &&
130 !TDETrader::self()->query(
"KRegExpEditor/KRegExpEditor").isEmpty();
131 regExpButton->setEnabled( isRegExp );
134 void SingleConditionWidget::showRegExpDialog()
136 TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>(
"KRegExpEditor/KRegExpEditor" );
137 if ( editorDialog ) {
138 KRegExpEditorInterface *editor =
static_cast<KRegExpEditorInterface *
>( editorDialog->tqt_cast(
"KRegExpEditorInterface" ) );
140 editor->setRegExp( expr->text() );
141 editorDialog->exec();
142 expr->setText( editor->regExp() );
151 ConditionEditWidget::ConditionEditWidget(KScoringManager *m, TQWidget *p,
const char *n)
158 ConditionEditWidget::~ConditionEditWidget()
168 Q_ASSERT( w->isA(
"SingleConditionWidget") );
174 void ConditionEditWidget::slotEditRule(KScoringRule *rule)
176 KScoringRule::ScoreExprList l;
177 if (rule) l = rule->getExpressions();
178 if (!rule || l.count() == 0) {
182 KScoringExpression *e = l.first();
185 scw->setCondition(e);
192 void ConditionEditWidget::updateRule(KScoringRule *rule)
194 rule->cleanExpressions();
196 if (! w->isA(
"SingleConditionWidget")) {
197 kdWarning(5100) <<
"there is a widget in ConditionEditWidget "
198 <<
"which isn't a SingleConditionWidget" << endl;
202 rule->addExpression(saw->createCondition());
212 SingleActionWidget::SingleActionWidget(KScoringManager *m,TQWidget *p,
const char *n)
213 : TQWidget(p,n), notifyEditor(0), scoreEditor(0), colorEditor(0),manager(m)
215 TQHBoxLayout *topL =
new TQHBoxLayout(
this,0,5);
216 types =
new KComboBox(
this);
217 types->setEditable(
false);
218 topL->addWidget(types);
219 stack =
new TQWidgetStack(
this);
220 topL->addWidget(stack);
222 dummyLabel =
new TQLabel(i18n(
"Select an action."), stack);
223 stack->addWidget(dummyLabel, 0);
227 types->insertItem(TQString());
228 TQStringList l = ActionBase::userNames();
229 for ( TQStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
231 int feature = ActionBase::getTypeForUserName(name);
232 if (manager->hasFeature(feature)) {
233 types->insertItem(name);
236 case ActionBase::SETSCORE:
237 w = scoreEditor =
new KIntSpinBox(-99999,99999,1,0,10, stack);
239 case ActionBase::NOTIFY:
240 w = notifyEditor =
new KLineEdit(stack);
242 case ActionBase::COLOR:
243 w = colorEditor =
new KColorCombo(stack);
245 case ActionBase::MARKASREAD:
246 w =
new TQLabel( stack );
250 stack->addWidget(w,index++);
254 connect(types,TQ_SIGNAL(activated(
int)),stack,TQ_SLOT(raiseWidget(
int)));
257 types->setCurrentItem(0);
258 stack->raiseWidget(dummyLabel);
261 SingleActionWidget::~SingleActionWidget()
265 void SingleActionWidget::setAction(
ActionBase *act)
267 kdDebug(5100) <<
"SingleActionWidget::setAction()" << endl;
268 setCurrentItem(types,ActionBase::userName(act->getType()));
269 int index = types->currentItem();
270 stack->raiseWidget(index);
271 switch (act->getType()) {
272 case ActionBase::SETSCORE:
273 scoreEditor->setValue(act->getValueString().toInt());
275 case ActionBase::NOTIFY:
276 notifyEditor->setText(act->getValueString());
278 case ActionBase::COLOR:
279 colorEditor->setColor(TQColor(act->getValueString()));
281 case ActionBase::MARKASREAD:
285 kdWarning(5100) <<
"unknown action type in SingleActionWidget::setAction()" << endl;
289 ActionBase* SingleActionWidget::createAction()
const
292 if (types->currentText().isEmpty())
295 int type = ActionBase::getTypeForUserName(types->currentText());
297 case ActionBase::SETSCORE:
298 return new ActionSetScore(scoreEditor->value());
299 case ActionBase::NOTIFY:
300 return new ActionNotify(notifyEditor->text());
301 case ActionBase::COLOR:
302 return new ActionColor(TQString(colorEditor->color().name()));
303 case ActionBase::MARKASREAD:
304 return new ActionMarkAsRead();
306 kdWarning(5100) <<
"unknown action type in SingleActionWidget::getValue()" << endl;
311 void SingleActionWidget::clear()
313 if (scoreEditor) scoreEditor->setValue(0);
314 if (notifyEditor) notifyEditor->clear();
315 if (colorEditor) colorEditor->setCurrentItem(0);
316 types->setCurrentItem(0);
317 stack->raiseWidget(dummyLabel);
325 ActionEditWidget::ActionEditWidget(KScoringManager *m,TQWidget *p,
const char *n)
332 ActionEditWidget::~ActionEditWidget()
340 void ActionEditWidget::slotEditRule(KScoringRule *rule)
342 KScoringRule::ActionList l;
343 if (rule) l = rule->getActions();
344 if (!rule || l.count() == 0) {
358 void ActionEditWidget::updateRule(KScoringRule *rule)
360 rule->cleanActions();
362 if (! w->isA(
"SingleActionWidget")) {
363 kdWarning(5100) <<
"there is a widget in ActionEditWidget "
364 <<
"which isn't a SingleActionWidget" << endl;
371 rule->addAction(act);
379 Q_ASSERT( w->isA(
"SingleActionWidget") );
390 RuleEditWidget::RuleEditWidget(KScoringManager *m,TQWidget *p,
const char *n)
391 : TQWidget(p,n), dirty(false), manager(m), oldRuleName(TQString())
393 kdDebug(5100) <<
"RuleEditWidget::RuleEditWidget()" << endl;
394 if ( !n ) setName(
"RuleEditWidget" );
395 TQVBoxLayout *topLayout =
new TQVBoxLayout(
this, 5, KDialog::spacingHint() );
398 TQGroupBox *groupB =
new TQGroupBox(i18n(
"Properties"),
this);
399 topLayout->addWidget(groupB);
400 TQGridLayout* groupL =
new TQGridLayout(groupB, 6,2, 8,5);
401 groupL->addRowSpacing(0, fontMetrics().lineSpacing()-4);
404 ruleNameEdit =
new KLineEdit( groupB,
"ruleNameEdit" );
405 groupL->addWidget( ruleNameEdit, 1, 1 );
406 TQLabel *ruleNameLabel =
new TQLabel(ruleNameEdit, i18n(
"&Name:"), groupB,
"ruleNameLabel");
407 groupL->addWidget( ruleNameLabel, 1, 0 );
410 groupsEdit =
new KLineEdit( groupB,
"groupsEdit" );
411 groupL->addWidget( groupsEdit, 2, 1 );
412 TQLabel *groupsLabel =
new TQLabel(groupsEdit, i18n(
"&Groups:"), groupB,
"groupsLabel");
413 groupL->addWidget( groupsLabel, 2, 0 );
415 TQPushButton *groupsBtn =
new TQPushButton(i18n(
"A&dd Group"), groupB);
416 connect(groupsBtn,TQ_SIGNAL(clicked()),TQ_SLOT(slotAddGroup()));
417 groupL->addWidget( groupsBtn, 3, 0 );
419 groupsBox =
new KComboBox(
false, groupB,
"groupsBox" );
420 groupsBox->setDuplicatesEnabled(
false);
421 groupsBox->insertStringList(manager->getGroups());
422 groupsBox->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
423 groupL->addWidget( groupsBox, 3, 1 );
426 expireCheck =
new TQCheckBox(i18n(
"&Expire rule automatically"), groupB);
427 groupL->addMultiCellWidget( expireCheck, 4,4, 0,1 );
428 expireEdit =
new KIntSpinBox(1,99999,1,30,10, groupB,
"expireWidget");
430 slotExpireEditChanged(30);
431 connect(expireEdit, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(slotExpireEditChanged(
int)));
432 groupL->addWidget( expireEdit, 5, 1 );
433 expireLabel =
new TQLabel(expireEdit, i18n(
"&Rule is valid for:"), groupB,
"expireLabel");
434 groupL->addWidget( expireLabel, 5, 0 );
435 expireLabel->setEnabled(
false);
436 expireEdit->setEnabled(
false);
438 connect(expireCheck, TQ_SIGNAL(toggled(
bool)), expireLabel, TQ_SLOT(setEnabled(
bool)));
439 connect(expireCheck, TQ_SIGNAL(toggled(
bool)), expireEdit, TQ_SLOT(setEnabled(
bool)));
442 TQGroupBox *groupConds =
new TQGroupBox(i18n(
"Conditions"),
this);
443 topLayout->addWidget(groupConds);
444 TQGridLayout *condL =
new TQGridLayout(groupConds, 3,2, 8,5);
446 condL->addRowSpacing(0, fontMetrics().lineSpacing()-4);
448 TQButtonGroup *buttonGroup =
new TQButtonGroup(groupConds);
450 linkModeAnd =
new TQRadioButton(i18n(
"Match a&ll conditions"), groupConds);
451 buttonGroup->insert(linkModeAnd);
452 condL->addWidget(linkModeAnd, 1,0);
453 linkModeOr =
new TQRadioButton(i18n(
"Matc&h any condition"), groupConds);
454 buttonGroup->insert(linkModeOr);
455 condL->addWidget(linkModeOr, 1,1);
456 linkModeAnd->setChecked(
true);
459 condL->addMultiCellWidget(condEditor, 2,2, 0,1);
460 connect(condEditor,TQ_SIGNAL(
widgetRemoved()),
this,TQ_SLOT(slotShrink()));
463 TQGroupBox *groupActions =
new TQGroupBox(i18n(
"Actions"),
this);
464 topLayout->addWidget(groupActions);
465 TQBoxLayout *actionL =
new TQVBoxLayout(groupActions,8,5);
466 actionL->addSpacing(fontMetrics().lineSpacing()-4);
468 actionL->addWidget(actionEditor);
469 connect(actionEditor,TQ_SIGNAL(
widgetRemoved()),
this,TQ_SLOT(slotShrink()));
471 topLayout->addStretch(1);
473 kdDebug(5100) <<
"constructed RuleEditWidget" << endl;
476 RuleEditWidget::~RuleEditWidget()
480 void RuleEditWidget::slotEditRule(
const TQString& ruleName)
482 kdDebug(5100) <<
"RuleEditWidget::slotEditRule(" << ruleName <<
")" << endl;
494 KScoringRule* rule = manager->findRule(ruleName);
496 kdDebug(5100) <<
"no rule for ruleName " << ruleName << endl;
500 oldRuleName = rule->getName();
501 ruleNameEdit->setText(rule->getName());
502 groupsEdit->setText(rule->getGroups().join(
";"));
504 bool b = rule->getExpireDate().isValid();
505 expireCheck->setChecked(b);
506 expireEdit->setEnabled(b);
507 expireLabel->setEnabled(b);
509 expireEdit->setValue(TQDate::currentDate().daysTo(rule->getExpireDate()));
511 expireEdit->setValue(30);
512 if (rule->getLinkMode() == KScoringRule::AND) {
513 linkModeAnd->setChecked(
true);
516 linkModeOr->setChecked(
true);
519 condEditor->slotEditRule(rule);
520 actionEditor->slotEditRule(rule);
522 kdDebug(5100) <<
"RuleEditWidget::slotEditRule() ready" << endl;
525 void RuleEditWidget::clearContents()
527 ruleNameEdit->setText(
"");
528 groupsEdit->setText(
"");
529 expireCheck->setChecked(
false);
530 expireEdit->setValue(30);
531 expireEdit->setEnabled(
false);
532 condEditor->slotEditRule(0);
533 actionEditor->slotEditRule(0);
534 oldRuleName = TQString();
537 void RuleEditWidget::updateRule(KScoringRule *rule)
539 oldRuleName = TQString();
540 TQString groups = groupsEdit->text();
541 if (groups.isEmpty())
542 rule->setGroups(TQStringList(
".*"));
544 rule->setGroups(TQStringList::split(
";",groups));
545 bool b = expireCheck->isChecked();
547 rule->setExpireDate(TQDate::currentDate().addDays(expireEdit->value()));
549 rule->setExpireDate(TQDate());
550 actionEditor->updateRule(rule);
551 rule->setLinkMode(linkModeAnd->isChecked()?KScoringRule::AND:KScoringRule::OR);
552 condEditor->updateRule(rule);
553 if (rule->getName() != ruleNameEdit->text())
554 manager->setRuleName(rule,ruleNameEdit->text());
557 void RuleEditWidget::updateRule()
559 KScoringRule *rule = manager->findRule(oldRuleName);
560 if (rule) updateRule(rule);
563 void RuleEditWidget::slotAddGroup()
565 TQString grp = groupsBox->currentText();
568 TQString txt = groupsEdit->text().stripWhiteSpace();
569 if ( txt ==
".*" || txt.isEmpty() ) groupsEdit->setText(grp);
570 else groupsEdit->setText(txt +
";" + grp);
573 void RuleEditWidget::setDirty()
575 kdDebug(5100) <<
"RuleEditWidget::setDirty()" << endl;
580 void RuleEditWidget::slotShrink()
585 void RuleEditWidget::slotExpireEditChanged(
int value)
587 expireEdit->setSuffix(i18n(
" day",
" days", value));
595 RuleListWidget::RuleListWidget(KScoringManager *m,
bool standalone, TQWidget *p,
const char *n)
596 : TQWidget(p,n), alone(standalone), manager(m)
598 kdDebug(5100) <<
"RuleListWidget::RuleListWidget()" << endl;
599 if (!n) setName(
"RuleListWidget");
600 TQVBoxLayout *topL =
new TQVBoxLayout(
this,standalone? 0:5,KDialog::spacingHint());
601 ruleList =
new TDEListBox(
this);
603 connect(ruleList,TQ_SIGNAL(doubleClicked(TQListBoxItem*)),
604 this,TQ_SLOT(slotEditRule(TQListBoxItem*)));
605 connect(ruleList,TQ_SIGNAL(returnPressed(TQListBoxItem*)),
606 this,TQ_SLOT(slotEditRule(TQListBoxItem*)));
608 connect(ruleList, TQ_SIGNAL(currentChanged(TQListBoxItem*)),
609 this, TQ_SLOT(slotRuleSelected(TQListBoxItem*)));
610 topL->addWidget(ruleList);
612 TQHBoxLayout *btnL =
new TQHBoxLayout( topL, KDialog::spacingHint() );
613 mRuleUp =
new TQPushButton(
this );
614 mRuleUp->setPixmap( BarIcon(
"go-up", TDEIcon::SizeSmall ) );
615 TQToolTip::add( mRuleUp, i18n(
"Move rule up") );
616 btnL->addWidget( mRuleUp );
617 connect( mRuleUp, TQ_SIGNAL( clicked() ), TQ_SLOT( slotRuleUp() ) );
618 mRuleDown =
new TQPushButton(
this );
619 mRuleDown->setPixmap( BarIcon(
"go-down", TDEIcon::SizeSmall ) );
620 TQToolTip::add( mRuleDown, i18n(
"Move rule down") );
621 btnL->addWidget( mRuleDown );
622 connect( mRuleDown, TQ_SIGNAL( clicked() ), TQ_SLOT( slotRuleDown() ) );
624 btnL =
new TQHBoxLayout( topL, KDialog::spacingHint() );
626 newRule =
new TQPushButton(
this);
627 newRule->setPixmap( BarIcon(
"document-new", TDEIcon::SizeSmall ) );
628 TQToolTip::add(newRule,i18n(
"New rule")),
629 btnL->addWidget(newRule);
630 connect(newRule, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotNewRule()));
633 editRule =
new TQPushButton(
this);
634 editRule->setIconSet( BarIconSet(
"edit", TDEIcon::SizeSmall) );
635 TQToolTip::add(editRule,i18n(
"Edit rule"));
636 btnL->addWidget(editRule);
637 connect(editRule,TQ_SIGNAL(clicked()),
this,TQ_SLOT(slotEditRule()));
639 delRule =
new TQPushButton(
this);
640 delRule->setIconSet( BarIconSet(
"edit-delete", TDEIcon::SizeSmall ) );
641 TQToolTip::add(delRule,i18n(
"Remove rule"));
642 btnL->addWidget(delRule);
643 connect(delRule, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotDelRule()));
644 copyRule =
new TQPushButton(
this);
645 copyRule->setIconSet(BarIconSet(
"edit-copy", TDEIcon::SizeSmall));
646 TQToolTip::add(copyRule,i18n(
"Copy rule"));
647 btnL->addWidget(copyRule);
648 connect(copyRule, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotCopyRule()));
651 TQBoxLayout *filterL =
new TQVBoxLayout(topL,KDialog::spacingHint());
652 KComboBox *filterBox =
new KComboBox(
this);
653 TQStringList l = m->getGroups();
654 filterBox->insertItem(i18n(
"<all groups>"));
655 filterBox->insertStringList(l);
656 filterBox->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed));
657 connect(filterBox,TQ_SIGNAL(activated(
const TQString&)),
658 this,TQ_SLOT(slotGroupFilter(
const TQString&)));
659 slotGroupFilter(i18n(
"<all groups>"));
660 TQLabel *lab =
new TQLabel(filterBox,i18n(
"Sho&w only rules for group:"),
this);
661 filterL->addWidget(lab);
662 filterL->addWidget(filterBox);
664 connect(manager,TQ_SIGNAL(changedRules()),
665 this,TQ_SLOT(updateRuleList()));
666 connect(manager,TQ_SIGNAL(changedRuleName(
const TQString&,
const TQString&)),
667 this,TQ_SLOT(slotRuleNameChanged(
const TQString&,
const TQString&)));
673 RuleListWidget::~RuleListWidget()
677 void RuleListWidget::updateButton()
679 bool state = ruleList->count() > 0;
681 editRule->setEnabled(state);
682 delRule->setEnabled(state);
683 copyRule->setEnabled(state);
685 TQListBoxItem *item = ruleList->item( ruleList->currentItem() );
687 mRuleUp->setEnabled( item->prev() != 0 );
688 mRuleDown->setEnabled( item->next() != 0 );
692 void RuleListWidget::updateRuleList()
695 kdDebug(5100) <<
"RuleListWidget::updateRuleList()" << endl;
696 TQString curr = ruleList->currentText();
698 if (group == i18n(
"<all groups>")) {
699 TQStringList l = manager->getRuleNames();
700 ruleList->insertStringList(l);
702 KScoringManager::ScoringRuleList l = manager->getAllRules();
703 for (KScoringRule* rule = l.first(); rule; rule = l.next() ) {
704 if (rule->matchGroup(group)) ruleList->insertItem(rule->getName());
707 int index = setCurrentItem(ruleList,curr);
709 ruleList->setCurrentItem(0);
710 slotRuleSelected(ruleList->currentText());
713 slotRuleSelected(curr);
717 void RuleListWidget::updateRuleList(
const KScoringRule *rule)
719 kdDebug(5100) <<
"RuleListWidget::updateRuleList(" << rule->getName() <<
")" << endl;
720 TQString name = rule->getName();
722 slotRuleSelected(name);
725 void RuleListWidget::slotRuleNameChanged(
const TQString& oldName,
const TQString& newName)
727 int ind = ruleList->currentItem();
728 for (uint i=0;i<ruleList->count();++i)
729 if (ruleList->text(i) == oldName) {
730 ruleList->changeItem(newName,i);
731 ruleList->setCurrentItem(ind);
736 void RuleListWidget::slotEditRule(
const TQString& s)
741 void RuleListWidget::slotEditRule()
743 if (ruleList->currentItem() >= 0) {
744 emit ruleEdited(ruleList->currentText());
746 else if (ruleList->count() == 0)
747 emit ruleEdited(TQString());
750 void RuleListWidget::slotEditRule(TQListBoxItem* item)
752 slotEditRule(item->text());
755 void RuleListWidget::slotGroupFilter(
const TQString& s)
761 void RuleListWidget::slotRuleSelected(
const TQString& ruleName)
764 kdDebug(5100) <<
"RuleListWidget::slotRuleSelected(" << ruleName <<
")" << endl;
765 if (ruleName != ruleList->currentText()) {
766 setCurrentItem(ruleList,ruleName);
769 emit ruleSelected(ruleName);
772 void RuleListWidget::slotRuleSelected(TQListBoxItem *item)
775 TQString ruleName = item->text();
776 slotRuleSelected(ruleName);
779 void RuleListWidget::slotRuleSelected(
int index)
782 if (idx >= ruleList->count())
return;
783 TQString ruleName = ruleList->text(index);
784 slotRuleSelected(ruleName);
787 void RuleListWidget::slotNewRule()
790 KScoringRule *rule = manager->addRule();
791 updateRuleList(rule);
792 if (alone) slotEditRule(rule->getName());
796 void RuleListWidget::slotDelRule()
798 KScoringRule *rule = manager->findRule(ruleList->currentText());
800 manager->deleteRule(rule);
802 if (!alone) slotEditRule();
806 void RuleListWidget::slotCopyRule()
809 TQString ruleName = ruleList->currentText();
810 KScoringRule *rule = manager->findRule(ruleName);
812 KScoringRule *nrule = manager->copyRule(rule);
813 updateRuleList(nrule);
814 slotEditRule(nrule->getName());
819 void RuleListWidget::slotRuleUp()
821 KScoringRule *rule = 0, *below = 0;
822 TQListBoxItem *item = ruleList->item( ruleList->currentItem() );
824 rule = manager->findRule( item->text() );
827 below = manager->findRule( item->text() );
830 manager->moveRuleAbove( rule, below );
835 void RuleListWidget::slotRuleDown()
837 KScoringRule *rule = 0, *above = 0;
838 TQListBoxItem *item = ruleList->item( ruleList->currentItem() );
840 rule = manager->findRule( item->text() );
843 above = manager->findRule( item->text() );
846 manager->moveRuleBelow( rule, above );
856 KScoringEditor* KScoringEditor::scoreEditor = 0;
858 KScoringEditor::KScoringEditor(KScoringManager* m,
859 TQWidget *parent,
const char *name)
860 : KDialogBase(parent,name,false,i18n(
"Rule Editor"),Ok|Apply|Cancel,Ok,true), manager(m)
862 manager->pushRuleList();
863 if (!scoreEditor) scoreEditor =
this;
864 kdDebug(5100) <<
"KScoringEditor::KScoringEditor()" << endl;
865 if (!name) setName(
"KScoringEditor");
868 TQWidget *w =
new TQWidget(
this);
870 TQHBoxLayout *hbl =
new TQHBoxLayout(w,0,spacingHint());
872 hbl->addWidget(ruleLister);
874 hbl->addWidget(ruleEditor);
875 connect(ruleLister,TQ_SIGNAL(ruleSelected(
const TQString&)),
876 ruleEditor, TQ_SLOT(slotEditRule(
const TQString&)));
877 connect(ruleLister, TQ_SIGNAL(leavingRule()),
878 ruleEditor, TQ_SLOT(updateRule()));
879 connect(ruleEditor, TQ_SIGNAL(shrink()), TQ_SLOT(slotShrink()));
880 connect(
this,TQ_SIGNAL(finished()),TQ_SLOT(slotFinished()));
881 ruleLister->slotRuleSelected(0);
882 resize(550, sizeHint().height());
885 void KScoringEditor::setDirty()
887 TQPushButton *applyBtn = actionButton(Apply);
888 applyBtn->setEnabled(
true);
891 KScoringEditor::~KScoringEditor()
896 KScoringEditor* KScoringEditor::createEditor(KScoringManager* m,
897 TQWidget *parent,
const char *name)
899 if (scoreEditor)
return scoreEditor;
900 else return new KScoringEditor(m,parent,name);
903 void KScoringEditor::setRule(KScoringRule* r)
905 kdDebug(5100) <<
"KScoringEditor::setRule(" << r->getName() <<
")" << endl;
906 TQString ruleName = r->getName();
907 ruleLister->slotRuleSelected(ruleName);
910 void KScoringEditor::slotShrink()
912 TQTimer::singleShot(5,
this, TQ_SLOT(slotDoShrink()));
915 void KScoringEditor::slotDoShrink()
918 TQApplication::sendPostedEvents();
919 resize(width(),sizeHint().height());
922 void KScoringEditor::slotApply()
924 TQString ruleName = ruleLister->currentRule();
925 KScoringRule *rule = manager->findRule(ruleName);
927 ruleEditor->updateRule(rule);
928 ruleLister->updateRuleList(rule);
930 manager->removeTOS();
931 manager->pushRuleList();
934 void KScoringEditor::slotOk()
937 manager->removeTOS();
938 KDialogBase::slotOk();
939 manager->editorReady();
942 void KScoringEditor::slotCancel()
944 manager->popRuleList();
945 KDialogBase::slotCancel();
948 void KScoringEditor::slotFinished()
958 KScoringEditorWidgetDialog::KScoringEditorWidgetDialog(KScoringManager *m,
const TQString& r, TQWidget *p,
const char *n)
959 : KDialogBase(p,n,true,i18n(
"Edit Rule"),
960 KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Close,
961 KDialogBase::Ok,true),
962 manager(m), ruleName(r)
964 TQFrame *f = makeMainWidget();
965 TQBoxLayout *topL =
new TQVBoxLayout(f);
967 connect(ruleEditor, TQ_SIGNAL(shrink()), TQ_SLOT(slotShrink()));
968 topL->addWidget(ruleEditor);
969 ruleEditor->slotEditRule(ruleName);
973 void KScoringEditorWidgetDialog::slotApply()
975 KScoringRule *rule = manager->findRule(ruleName);
977 ruleEditor->updateRule(rule);
978 ruleName = rule->getName();
982 void KScoringEditorWidgetDialog::slotOk()
985 KDialogBase::slotOk();
988 void KScoringEditorWidgetDialog::slotShrink()
990 TQTimer::singleShot(5,
this, TQ_SLOT(slotDoShrink()));
993 void KScoringEditorWidgetDialog::slotDoShrink()
996 TQApplication::sendPostedEvents();
997 resize(width(),sizeHint().height());
1005 KScoringEditorWidget::KScoringEditorWidget(KScoringManager *m,TQWidget *p,
const char *n)
1006 : TQWidget(p,n), manager(m)
1008 TQBoxLayout *topL =
new TQVBoxLayout(
this);
1010 topL->addWidget(ruleLister);
1011 connect(ruleLister,TQ_SIGNAL(ruleEdited(
const TQString&)),
1012 this,TQ_SLOT(slotRuleEdited(
const TQString &)));
1015 KScoringEditorWidget::~KScoringEditorWidget()
1017 manager->editorReady();
1020 void KScoringEditorWidget::slotRuleEdited(
const TQString& ruleName)
1022 KScoringEditorWidgetDialog dlg(manager,ruleName,
this);
1024 ruleLister->updateRuleList();
1027 #include "kscoringeditor.moc"
Base class for other Action classes.