[konversation] /: Color text past TOPICLEN in KColorScheme::NegativeText.
Eike Hein <hein <at> kde.org>
2012-05-22 23:54:24 GMT
Git commit f1eb0fb703fd22cd0f6ffcbd71a0a3f3bce93135 by Eike Hein.
Committed on 23/05/2012 at 01:55.
Pushed by hein into branch 'master'.
Color text past TOPICLEN in KColorScheme::NegativeText.
M +3 -0 ChangeLog
M +50 -0 src/irc/channeloptionsdialog.cpp
M +2 -0 src/irc/channeloptionsdialog.h
http://commits.kde.org/konversation/f1eb0fb703fd22cd0f6ffcbd71a0a3f3bce93135
diff --git a/ChangeLog b/ChangeLog
index 0d9c38b..c29e280 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -101,6 +101,9 @@ Changes not in the 1.4 branch:
Buttons that operate on nicknames will be shown alongside other nickname-
related actions in context menus throughout Konversation. Essentially, this
allows for placing custom actions in nickname context menus.
+* When editing the topic in the Channel Options dialog, any text entered past the
+ server's maximum allowed topic length will now be drawn in the color scheme's
+ negative text color (i.e. usually red).
Changes since 1.4:
diff --git a/src/irc/channeloptionsdialog.cpp b/src/irc/channeloptionsdialog.cpp
index bc46d79..693ff58 100644
--- a/src/irc/channeloptionsdialog.cpp
+++ b/src/irc/channeloptionsdialog.cpp
@@ -15,6 +15,8 @@
#include "application.h"
#include "channel.h"
+#include <KColorScheme>
+
#include <QCheckBox>
#include <QHeaderView>
#include <QPushButton>
@@ -52,11 +54,13 @@ namespace Konversation
m_channel = channel;
m_editingTopic = false;
+ m_previousEditPastTopicLength = false;
connect(m_ui.topicHistoryView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(topicHistoryItemClicked(QItemSelection)));
connect(m_ui.toggleAdvancedModes, SIGNAL(clicked()), this, SLOT(toggleAdvancedModes()));
connect(m_ui.topicEdit, SIGNAL(undoAvailable(bool)), this, SLOT(topicBeingEdited(bool)));
+ connect(m_ui.topicEdit->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(topicEditContentsChange(int,int,int)));
connect(this, SIGNAL(finished()), m_ui.topicEdit, SLOT(clear()));
connect(m_channel, SIGNAL(topicHistoryChanged()), this, SLOT(refreshTopicHistory()));
@@ -169,6 +173,52 @@ namespace Konversation
m_editingTopic = edited;
}
+ void ChannelOptionsDialog::topicEditContentsChange(int position, int charsRemoved, int charsAdded)
+ {
+ if (!m_editingTopic) return;
+ if (charsRemoved == 0 && charsAdded == 0) return;
+
+ int topicLength = m_channel->getServer()->topicLength();
+
+ if (topicLength == -1) return;
+
+ if (m_ui.topicEdit->document()->characterCount() > topicLength)
+ {
+ m_previousEditPastTopicLength = true;
+
+ QTextCursor cursor(m_ui.topicEdit->document());
+ QTextCharFormat format = cursor.charFormat();
+
+ cursor.joinPreviousEditBlock();
+
+ cursor.setPosition(topicLength, QTextCursor::KeepAnchor);
+ cursor.setCharFormat(format);
+
+ cursor.setPosition(topicLength, QTextCursor::MoveAnchor);
+ cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
+
+ KColorScheme colors(QPalette::Active);
+ format.setForeground(colors.foreground(KColorScheme::NegativeText));
+ cursor.setCharFormat(format);
+
+ cursor.endEditBlock();
+ }
+ else if (m_previousEditPastTopicLength)
+ {
+ m_previousEditPastTopicLength = false;
+
+ QTextCursor cursor(m_ui.topicEdit->document());
+ QTextCharFormat format = cursor.charFormat();
+
+ cursor.joinPreviousEditBlock();
+
+ cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
+ cursor.setCharFormat(format);
+
+ cursor.endEditBlock();
+ }
+ }
+
QString ChannelOptionsDialog::topic()
{
return m_ui.topicEdit->toPlainText().replace('\n',' ');
diff --git a/src/irc/channeloptionsdialog.h b/src/irc/channeloptionsdialog.h
index 8dde675..42a0191 100644
--- a/src/irc/channeloptionsdialog.h
+++ b/src/irc/channeloptionsdialog.h
@@ -64,9 +64,11 @@ namespace Konversation
protected slots:
void topicHistoryItemClicked(const QItemSelection& selection);
void topicBeingEdited(bool edited);
+ void topicEditContentsChange(int position, int charsRemoved, int charsAdded);
protected:
bool m_editingTopic;
+ bool m_previousEditPastTopicLength;
bool m_isAnyTypeOfOp;
private: