+
+void TopicWidget::updateResizeMode()
+{
+ StyledLabel::ResizeMode mode = StyledLabel::NoResize;
+ UiSettings s("TopicWidget");
+ if (s.value("DynamicResize", true).toBool()) {
+ if (s.value("ResizeOnHover", true).toBool())
+ mode = StyledLabel::ResizeOnHover;
+ else
+ mode = StyledLabel::DynamicResize;
+ }
+
+ ui.topicLabel->setResizeMode(mode);
+}
+
+
+void TopicWidget::clickableActivated(const Clickable &click)
+{
+ NetworkId networkId = selectionModel()->currentIndex().data(NetworkModel::NetworkIdRole).value<NetworkId>();
+ UiStyle::StyledString sstr = GraphicalUi::uiStyle()->styleString(GraphicalUi::uiStyle()->mircToInternal(_topic), UiStyle::PlainMsg);
+ click.activate(networkId, sstr.plainText);
+}
+
+
+void TopicWidget::on_topicLineEdit_textEntered()
+{
+ QModelIndex currentIdx = currentIndex();
+ if (currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
+ BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
+ if (ui.topicLineEdit->text().isEmpty())
+ Client::userInput(bufferInfo, QString("/quote TOPIC %1 :").arg(bufferInfo.bufferName()));
+ else
+ Client::userInput(bufferInfo, QString("/topic %1").arg(ui.topicLineEdit->text()));
+ }
+ switchPlain();
+}
+
+
+void TopicWidget::on_topicEditButton_clicked()
+{
+ switchEditable();
+}
+
+
+void TopicWidget::switchEditable()
+{
+ ui.stackedWidget->setCurrentIndex(1);
+ ui.topicLineEdit->setFocus();
+ ui.topicLineEdit->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
+ updateGeometry();
+}
+
+
+void TopicWidget::switchPlain()
+{
+ ui.stackedWidget->setCurrentIndex(0);
+ ui.topicLineEdit->setPlainText(_topic);
+ updateGeometry();
+ emit switchedPlain();
+}
+
+
+// filter for the input widget to switch back to normal mode
+bool TopicWidget::eventFilter(QObject *obj, QEvent *event)
+{
+ if (event->type() == QEvent::FocusOut && !_mouseEntered) {
+ switchPlain();
+ return true;
+ }
+
+ if (event->type() == QEvent::Enter) {
+ _mouseEntered = true;
+ }
+
+ if (event->type() == QEvent::Leave) {
+ _mouseEntered = false;
+ }
+
+ if (event->type() != QEvent::KeyRelease)
+ return QObject::eventFilter(obj, event);
+
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+
+ if (keyEvent->key() == Qt::Key_Escape) {
+ switchPlain();
+ return true;
+ }
+
+ return false;
+}
+
+QString TopicWidget::sanitizeTopic(const QString& topic)
+{
+ // Normally, you don't have new lines in topic messages
+ // But the use of "plain text" functionnality from Qt replaces
+ // some unicode characters with a new line, which then triggers
+ // a stack overflow later
+ QString result(topic);
+#if QT_VERSION >= 0x050000
+ result.replace(QChar::CarriageReturn, " ");
+#endif
+ result.replace(QChar::ParagraphSeparator, " ");
+ result.replace(QChar::LineSeparator, " ");
+
+ return result;