- }
-};
-
-void InputWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
- NetworkId networkId;
- QModelIndex child;
- for(int row = start; row <= end; row++) {
- child = model()->index(row, 0, parent);
- if(NetworkModel::NetworkItemType != child.data(NetworkModel::ItemTypeRole).toInt())
- continue;
- networkId = child.data(NetworkModel::NetworkIdRole).value<NetworkId>();
- if(networkId == _networkId) {
- setNetwork(0);
- updateNickSelector();
- return;
- }
- }
-}
-
-void InputWidget::updateEnabledState() {
- QModelIndex currentIndex = selectionModel()->currentIndex();
-
- const Network *net = Client::networkModel()->networkByIndex(currentIndex);
- bool enabled = false;
- if(net) {
- // disable inputline if it's a channelbuffer we parted from or...
- enabled = (currentIndex.data(NetworkModel::ItemActiveRole).value<bool>() || (currentIndex.data(NetworkModel::BufferTypeRole).toInt() != BufferInfo::ChannelBuffer));
- // ... if we're not connected to the network at all
- enabled &= net->isConnected();
- }
- ui.inputEdit->setEnabled(enabled);
-}
-
-const Network *InputWidget::currentNetwork() const {
- return Client::network(_networkId);
-}
-
-BufferInfo InputWidget::currentBufferInfo() const {
- return selectionModel()->currentIndex().data(NetworkModel::BufferInfoRole).value<BufferInfo>();
-};
-
-void InputWidget::setNetwork(NetworkId networkId) {
- if(_networkId == networkId)
- return;
-
- const Network *previousNet = Client::network(_networkId);
- if(previousNet) {
- disconnect(previousNet, 0, this, 0);
- if(previousNet->me())
- disconnect(previousNet->me(), 0, this, 0);
- }
-
- _networkId = networkId;
-
- const Network *network = Client::network(networkId);
- if(network) {
- connect(network, SIGNAL(identitySet(IdentityId)), this, SLOT(setIdentity(IdentityId)));
- connectMyIrcUser();
- setIdentity(network->identity());
- } else {
- setIdentity(0);
- _networkId = 0;
- }
-}
-
-void InputWidget::connectMyIrcUser() {
- const Network *network = currentNetwork();
- if(network->me()) {
- connect(network->me(), SIGNAL(nickSet(const QString &)), this, SLOT(updateNickSelector()));
- connect(network->me(), SIGNAL(userModesSet(QString)), this, SLOT(updateNickSelector()));
- connect(network->me(), SIGNAL(userModesAdded(QString)), this, SLOT(updateNickSelector()));
- connect(network->me(), SIGNAL(userModesRemoved(QString)), this, SLOT(updateNickSelector()));
- connect(network->me(), SIGNAL(awaySet(bool)), this, SLOT(updateNickSelector()));
- disconnect(network, SIGNAL(myNickSet(const QString &)), this, SLOT(connectMyIrcUser()));
+}
+
+void InputWidget::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
+{
+ QItemSelectionRange changedArea(topLeft, bottomRight);
+ if (changedArea.contains(selectionModel()->currentIndex())) {
+ updateEnabledState();
+
+ bool encrypted = false;
+
+ auto* chan = qobject_cast<IrcChannel*>(
+ Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcChannelRole).value<QObject*>());
+ if (chan)
+ encrypted = chan->encrypted();
+
+ auto* user = qobject_cast<IrcUser*>(
+ Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcUserRole).value<QObject*>());
+ if (user)
+ encrypted = user->encrypted();
+
+ if (encrypted)
+ ui.encryptionIconLabel->show();
+ else
+ ui.encryptionIconLabel->hide();
+ }
+}
+
+void InputWidget::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
+{
+ NetworkId networkId;
+ QModelIndex child;
+ for (int row = start; row <= end; row++) {
+ child = model()->index(row, 0, parent);
+ if (NetworkModel::NetworkItemType != child.data(NetworkModel::ItemTypeRole).toInt())
+ continue;
+ networkId = child.data(NetworkModel::NetworkIdRole).value<NetworkId>();
+ if (networkId == _networkId) {
+ setNetwork(0);
+ updateNickSelector();
+ return;
+ }
+ }
+}
+
+void InputWidget::updateEnabledState()
+{
+// FIXME: Find a visualization for this that does not disable the widget!
+// Disabling kills global action shortcuts, plus users sometimes need/want to enter text
+// even in inactive channels.
+#if 0
+ QModelIndex currentIndex = selectionModel()->currentIndex();
+
+ const Network *net = Client::networkModel()->networkByIndex(currentIndex);
+ bool enabled = false;
+ if (net) {
+ // disable inputline if it's a channelbuffer we parted from or...
+ enabled = (currentIndex.data(NetworkModel::ItemActiveRole).value<bool>() || (currentIndex.data(NetworkModel::BufferTypeRole).toInt() != BufferInfo::ChannelBuffer));
+ // ... if we're not connected to the network at all
+ enabled &= net->isConnected();
+ }
+
+ ui.inputEdit->setEnabled(enabled);
+#endif
+}
+
+const Network* InputWidget::currentNetwork() const
+{
+ return Client::network(_networkId);
+}
+
+BufferInfo InputWidget::currentBufferInfo() const
+{
+ return selectionModel()->currentIndex().data(NetworkModel::BufferInfoRole).value<BufferInfo>();
+}
+
+void InputWidget::applyFormatActiveColor()
+{
+ if (!ui.textcolorButton->defaultAction()) {
+ return;
+ }
+ colorChosen(ui.textcolorButton->defaultAction());
+}
+
+void InputWidget::applyFormatActiveColorFill()
+{
+ if (!ui.highlightcolorButton->defaultAction()) {
+ return;
+ }
+ colorHighlightChosen(ui.highlightcolorButton->defaultAction());
+}
+
+void InputWidget::toggleFormatBold()
+{
+ setFormatBold(!ui.boldButton->isChecked());
+}
+
+void InputWidget::toggleFormatItalic()
+{
+ setFormatItalic(!ui.italicButton->isChecked());
+}
+
+void InputWidget::toggleFormatUnderline()
+{
+ setFormatUnderline(!ui.underlineButton->isChecked());
+}
+
+void InputWidget::toggleFormatStrikethrough()
+{
+ setFormatStrikethrough(!ui.strikethroughButton->isChecked());
+}
+
+void InputWidget::clearFormat()
+{
+ // Clear all formatting for selection (not global)
+ setFormatClear(false);
+}
+
+void InputWidget::setNetwork(NetworkId networkId)
+{
+ if (_networkId == networkId)
+ return;
+
+ const Network* previousNet = Client::network(_networkId);
+ if (previousNet) {
+ disconnect(previousNet, nullptr, this, nullptr);
+ if (previousNet->me())
+ disconnect(previousNet->me(), nullptr, this, nullptr);
+ }
+
+ _networkId = networkId;
+
+ const Network* network = Client::network(networkId);
+ if (network) {
+ connect(network, &Network::identitySet, this, &InputWidget::setIdentity);
+ connectMyIrcUser();
+ setIdentity(network->identity());
+ }
+ else {
+ setIdentity(0);
+ _networkId = 0;
+ }
+}
+
+void InputWidget::connectMyIrcUser()
+{
+ const Network* network = currentNetwork();
+ if (network->me()) {
+ connect(network->me(), &IrcUser::nickSet, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesSet, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesAdded, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesRemoved, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::awaySet, this, &InputWidget::updateNickSelector);
+ disconnect(network, &Network::myNickSet, this, &InputWidget::connectMyIrcUser);
+ updateNickSelector();
+ }
+ else {
+ connect(network, &Network::myNickSet, this, &InputWidget::connectMyIrcUser);
+ }
+}
+
+void InputWidget::setIdentity(IdentityId identityId)
+{
+ if (_identityId == identityId)
+ return;
+
+ const Identity* previousIdentity = Client::identity(_identityId);
+ if (previousIdentity)
+ disconnect(previousIdentity, nullptr, this, nullptr);
+
+ _identityId = identityId;
+
+ const Identity* identity = Client::identity(identityId);
+ if (identity) {
+ connect(identity, &Identity::nicksSet, this, &InputWidget::updateNickSelector);
+ }
+ else {
+ _identityId = 0;
+ }