diff options
| -rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 146 | ||||
| -rw-r--r-- | Swift/QtUI/QtHighlightEditor.h | 2 | ||||
| -rw-r--r-- | Swift/QtUI/QtHighlightEditor.ui | 38 | 
3 files changed, 124 insertions, 62 deletions
| diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index bd52e2d..8a27a09 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -60,17 +60,17 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare  	connect(ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(onCancelButtonClick()));  	connect(ui_.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(onOkButtonClick())); -	connect(ui_.radioButton, SIGNAL(clicked()), SLOT(colorOtherSelect())); -	connect(ui_.radioButton_2, SIGNAL(clicked()), SLOT(colorOtherSelect())); -	connect(ui_.radioButton_7, SIGNAL(clicked()), SLOT(colorCustomSelect())); +	connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect())); +	connect(ui_.defaultColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect())); +	connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(colorCustomSelect())); -	connect(ui_.radioButton_4, SIGNAL(clicked()), SLOT(soundOtherSelect())); -	connect(ui_.radioButton_5, SIGNAL(clicked()), SLOT(soundOtherSelect())); -	connect(ui_.radioButton_6, SIGNAL(clicked()), SLOT(soundCustomSelect())); +	connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect())); +	connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect())); +	connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(soundCustomSelect())); -	ui_.lineEdit->setVisible(false); +	ui_.dummySenderName->setVisible(false);  	jid_ = new QtSuggestingJIDInput(this, settings); -	ui_.horizontalLayout_2->addWidget(jid_); +	ui_.senderName->addWidget(jid_);  	setWindowTitle(tr("Highlight Rules"));  } @@ -162,14 +162,14 @@ void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager)  void QtHighlightEditor::colorOtherSelect()  { -	ui_.foreground_2->setEnabled(false); -	ui_.background->setEnabled(false); +	ui_.foregoundColor->setEnabled(false); +	ui_.backgroundColor->setEnabled(false);  }  void QtHighlightEditor::colorCustomSelect()  { -	ui_.foreground_2->setEnabled(true); -	ui_.background->setEnabled(true); +	ui_.foregoundColor->setEnabled(true); +	ui_.backgroundColor->setEnabled(true);  }  void QtHighlightEditor::soundOtherSelect() @@ -197,8 +197,10 @@ void QtHighlightEditor::onNewButtonClicked()  void QtHighlightEditor::onDeleteButtonClicked()  {  	int selectedRow = getSelectedRow(); -	delete ui_.listWidget->takeItem(selectedRow); -	highlightManager_->removeRule(selectedRow); +	if (selectedRow == -1) { +		delete ui_.listWidget->takeItem(selectedRow); +		highlightManager_->removeRule(selectedRow); +	}  }  void QtHighlightEditor::onMoveUpButtonClicked() @@ -243,11 +245,14 @@ void QtHighlightEditor::onCurrentRowChanged(int currentRow)  	if (currentRow != -1) {  		ruleToDialog(highlightManager_->getRule(currentRow)); -	} else { -		/* grey/disable entire dialog */  	} +	/* grey the dialog if we have nothing selected */ +	enableDialog(currentRow != -1); +  	previousRow_ = currentRow; + +	updateRuleDescription();  }  void QtHighlightEditor::onApplyButtonClick() @@ -267,6 +272,51 @@ void QtHighlightEditor::onOkButtonClick()  	close();  } +void QtHighlightEditor::updateRuleDescription() +{ +	ui_.ruleDescription->setText(P2QSTRING(formatNaturalDescription(ruleFromDialog()))); +} + +void QtHighlightEditor::enableDialog(bool state) +{ +	if (!state) { /* also clear the value, if applicable */ +		ui_.chatCheck->setChecked(false); +		ui_.roomCheck->setChecked(false); +		ui_.senderCheck->setChecked(false); +		jid_->setText(""); +		ui_.keywordCheck->setChecked(false); +		ui_.keyword->setText(""); +		ui_.nickIsKeyword->setChecked(false); +		ui_.matchWholeWords->setChecked(false); +		ui_.matchCase->setChecked(false); +		ui_.noColorRadio->setChecked(true); +		//ui_.foregoundColor->setEnabled(state); +		//ui_.backgroundColor->setEnabled(state); +		ui_.noSoundRadio->setChecked(true); +		ui_.soundFile->setText(""); +	} + +	ui_.chatCheck->setEnabled(state); +	ui_.roomCheck->setEnabled(state); +	ui_.senderCheck->setEnabled(state); +	jid_->setEnabled(state); +	ui_.keywordCheck->setEnabled(state); +	ui_.keyword->setEnabled(state); +	ui_.nickIsKeyword->setEnabled(state); +	ui_.matchWholeWords->setEnabled(state); +	ui_.matchCase->setEnabled(state); +	ui_.noColorRadio->setEnabled(state); +	ui_.defaultColorRadio->setEnabled(state); +	ui_.customColorRadio->setEnabled(state); +	ui_.foregoundColor->setEnabled(state); +	ui_.backgroundColor->setEnabled(state); +	ui_.noSoundRadio->setEnabled(state); +	ui_.defaultSoundRadio->setEnabled(state); +	ui_.customSoundRadio->setEnabled(state); +	ui_.soundFile->setEnabled(state); +	ui_.soundFileButton->setEnabled(state); +} +  void QtHighlightEditor::selectRow(int row)  {  	for (int i = 0; i < ui_.listWidget->count(); ++i) { @@ -293,10 +343,10 @@ HighlightRule QtHighlightEditor::ruleFromDialog()  {  	HighlightRule rule; -	rule.setMatchChat(ui_.checkBox->isChecked()); -	rule.setMatchMUC(ui_.checkBox_2->isChecked()); +	rule.setMatchChat(ui_.chatCheck->isChecked()); +	rule.setMatchMUC(ui_.roomCheck->isChecked()); -	if (ui_.checkBox_3->isChecked()) { +	if (ui_.senderCheck->isChecked()) {  		QString senderName = jid_->text();  		if (!senderName.isEmpty()) {  			std::vector<std::string> senders; @@ -305,8 +355,8 @@ HighlightRule QtHighlightEditor::ruleFromDialog()  		}  	} -	if (ui_.checkBox_4->isChecked()) { -		QString keywordString = ui_.lineEdit_2->text(); +	if (ui_.keywordCheck->isChecked()) { +		QString keywordString = ui_.keyword->text();  		if (!keywordString.isEmpty()) {  			std::vector<std::string> keywords;  			keywords.push_back(Q2PSTRING(keywordString)); @@ -315,14 +365,14 @@ HighlightRule QtHighlightEditor::ruleFromDialog()  	}  	rule.setNickIsKeyword(ui_.nickIsKeyword->isChecked()); -	rule.setMatchWholeWords(ui_.matchWholeWords_2->isChecked()); -	rule.setMatchCase(ui_.matchCase_2->isChecked()); +	rule.setMatchWholeWords(ui_.matchWholeWords->isChecked()); +	rule.setMatchCase(ui_.matchCase->isChecked());  	HighlightAction& action = rule.getAction(); -	if (ui_.radioButton->isChecked()) { +	if (ui_.noColorRadio->isChecked()) {  		action.setHighlightText(false); -	} else if (ui_.radioButton_2->isChecked()) { +	} else if (ui_.defaultColorRadio->isChecked()) {  		action.setHighlightText(true);  		action.setTextColor("");  		action.setTextBackground(""); @@ -332,60 +382,70 @@ HighlightRule QtHighlightEditor::ruleFromDialog()  		action.setTextBackground("#ffffffff");  	} +	if (ui_.noSoundRadio->isChecked()) { +		action.setPlaySound(false); +	} else if (ui_.defaultSoundRadio->isChecked()) { +		action.setPlaySound(true); +		action.setSoundFile(""); +	} else { +		action.setPlaySound(true); +		action.setSoundFile(Q2PSTRING(ui_.soundFile->text())); +	} +  	return rule;  }  void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)  { -	ui_.checkBox->setChecked(rule.getMatchChat()); -	ui_.checkBox_2->setChecked(rule.getMatchMUC()); +	ui_.chatCheck->setChecked(rule.getMatchChat()); +	ui_.roomCheck->setChecked(rule.getMatchMUC());  	std::vector<std::string> senders = rule.getSenders();  	if (senders.empty()) { -		ui_.checkBox_3->setChecked(false); +		ui_.senderCheck->setChecked(false);  		jid_->setEnabled(false);  		jid_->setText("");  	} else { -		ui_.checkBox_3->setChecked(true); +		ui_.senderCheck->setChecked(true);  		jid_->setEnabled(true);  		jid_->setText(P2QSTRING(senders[0]));  	}  	std::vector<std::string> keywords = rule.getKeywords();  	if (keywords.empty()) { -		ui_.checkBox_4->setChecked(false); -		ui_.lineEdit_2->setEnabled(false); -		ui_.lineEdit_2->setText(""); +		ui_.keywordCheck->setChecked(false); +		ui_.keyword->setEnabled(false); +		ui_.keyword->setText("");  	} else { -		ui_.checkBox_4->setChecked(true); -		ui_.lineEdit_2->setEnabled(true); -		ui_.lineEdit_2->setText(P2QSTRING(keywords[0])); +		ui_.keywordCheck->setChecked(true); +		ui_.keyword->setEnabled(true); +		ui_.keyword->setText(P2QSTRING(keywords[0]));  	}  	ui_.nickIsKeyword->setChecked(rule.getNickIsKeyword()); -	ui_.matchWholeWords_2->setChecked(rule.getMatchWholeWords()); -	ui_.matchCase_2->setChecked(rule.getMatchCase()); +	ui_.matchWholeWords->setChecked(rule.getMatchWholeWords()); +	ui_.matchCase->setChecked(rule.getMatchCase());  	const HighlightAction& action = rule.getAction();  	if (action.highlightText()) {  		if (action.getTextColor().empty() && action.getTextBackground().empty()) { -			ui_.radioButton_2->setChecked(true); +			ui_.defaultColorRadio->setChecked(true);  		} else { -			ui_.radioButton_7->setChecked(true); +			ui_.customColorRadio->setChecked(true);  		}  	} else { -		ui_.radioButton->setChecked(true); +		ui_.noColorRadio->setChecked(true);  	}  	if (action.playSound()) {  		if (action.getSoundFile().empty()) { -			ui_.radioButton_5->setChecked(true); +			ui_.defaultSoundRadio->setChecked(true);  		} else { -			ui_.radioButton_6->setChecked(true); +			ui_.customSoundRadio->setChecked(true);  		}  	} else { -		ui_.radioButton_4->setChecked(true); +		ui_.noSoundRadio->setChecked(true);  	}  } diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index b195c13..bd35736 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -44,6 +44,8 @@ namespace Swift {  			void onApplyButtonClick();  			void onCancelButtonClick();  			void onOkButtonClick(); +			void updateRuleDescription(); +			void enableDialog(bool state);  		private: diff --git a/Swift/QtUI/QtHighlightEditor.ui b/Swift/QtUI/QtHighlightEditor.ui index 8355381..0de6ba5 100644 --- a/Swift/QtUI/QtHighlightEditor.ui +++ b/Swift/QtUI/QtHighlightEditor.ui @@ -126,7 +126,7 @@           </property>           <layout class="QHBoxLayout" name="horizontalLayout_11">            <item> -           <widget class="QTextEdit" name="textEdit_2"> +           <widget class="QTextEdit" name="ruleDescription">              <property name="html">               <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">  <html><head><meta name="qrichtext" content="1" /><style type="text/css"> @@ -146,7 +146,7 @@ p, li { white-space: pre-wrap; }           </property>           <layout class="QHBoxLayout" name="horizontalLayout_10">            <item> -           <widget class="QTextEdit" name="textEdit"/> +           <widget class="QTextEdit" name="chatExample"/>            </item>           </layout>          </widget> @@ -171,14 +171,14 @@ p, li { white-space: pre-wrap; }               </widget>              </item>              <item> -             <widget class="QCheckBox" name="checkBox"> +             <widget class="QCheckBox" name="chatCheck">                <property name="text">                 <string>Chats</string>                </property>               </widget>              </item>              <item> -             <widget class="QCheckBox" name="checkBox_2"> +             <widget class="QCheckBox" name="roomCheck">                <property name="text">                 <string>Rooms</string>                </property> @@ -200,30 +200,30 @@ p, li { white-space: pre-wrap; }             </layout>            </item>            <item> -           <layout class="QHBoxLayout" name="horizontalLayout_2"> +           <layout class="QHBoxLayout" name="senderName">              <item> -             <widget class="QCheckBox" name="checkBox_3"> +             <widget class="QCheckBox" name="senderCheck">                <property name="text">                 <string>Sender name:</string>                </property>               </widget>              </item>              <item> -             <widget class="QLineEdit" name="lineEdit"/> +             <widget class="QLineEdit" name="dummySenderName"/>              </item>             </layout>            </item>            <item>             <layout class="QHBoxLayout" name="horizontalLayout_4">              <item> -             <widget class="QCheckBox" name="checkBox_4"> +             <widget class="QCheckBox" name="keywordCheck">                <property name="text">                 <string>Keyword:</string>                </property>               </widget>              </item>              <item> -             <widget class="QLineEdit" name="lineEdit_2"/> +             <widget class="QLineEdit" name="keyword"/>              </item>             </layout>            </item> @@ -237,14 +237,14 @@ p, li { white-space: pre-wrap; }               </widget>              </item>              <item> -             <widget class="QCheckBox" name="matchWholeWords_2"> +             <widget class="QCheckBox" name="matchWholeWords">                <property name="text">                 <string>Match keyword within longer words</string>                </property>               </widget>              </item>              <item> -             <widget class="QCheckBox" name="matchCase_2"> +             <widget class="QCheckBox" name="matchCase">                <property name="text">                 <string>Keyword is case sensitive</string>                </property> @@ -264,7 +264,7 @@ p, li { white-space: pre-wrap; }            <item>             <layout class="QHBoxLayout" name="horizontalLayout_5">              <item> -             <widget class="QRadioButton" name="radioButton"> +             <widget class="QRadioButton" name="noColorRadio">                <property name="text">                 <string>No Highlight</string>                </property> @@ -274,14 +274,14 @@ p, li { white-space: pre-wrap; }               </widget>              </item>              <item> -             <widget class="QRadioButton" name="radioButton_2"> +             <widget class="QRadioButton" name="defaultColorRadio">                <property name="text">                 <string>Default Color</string>                </property>               </widget>              </item>              <item> -             <widget class="QRadioButton" name="radioButton_7"> +             <widget class="QRadioButton" name="customColorRadio">                <property name="text">                 <string>Custom Color</string>                </property> @@ -318,7 +318,7 @@ p, li { white-space: pre-wrap; }               </spacer>              </item>              <item> -             <widget class="Swift::QtColorToolButton" name="foreground_2"> +             <widget class="Swift::QtColorToolButton" name="foregoundColor">                <property name="enabled">                 <bool>false</bool>                </property> @@ -331,7 +331,7 @@ p, li { white-space: pre-wrap; }               </widget>              </item>              <item> -             <widget class="Swift::QtColorToolButton" name="background"> +             <widget class="Swift::QtColorToolButton" name="backgroundColor">                <property name="enabled">                 <bool>false</bool>                </property> @@ -357,7 +357,7 @@ p, li { white-space: pre-wrap; }            <item>             <layout class="QHBoxLayout" name="horizontalLayout_7">              <item> -             <widget class="QRadioButton" name="radioButton_4"> +             <widget class="QRadioButton" name="noSoundRadio">                <property name="text">                 <string>No Sound</string>                </property> @@ -367,14 +367,14 @@ p, li { white-space: pre-wrap; }               </widget>              </item>              <item> -             <widget class="QRadioButton" name="radioButton_5"> +             <widget class="QRadioButton" name="defaultSoundRadio">                <property name="text">                 <string>Default Sound</string>                </property>               </widget>              </item>              <item> -             <widget class="QRadioButton" name="radioButton_6"> +             <widget class="QRadioButton" name="customSoundRadio">                <property name="text">                 <string>Custom Sound</string>                </property> | 
 Swift
 Swift