+
+QVariant AliasesModel::data(const QModelIndex &index, int role) const
+{
+ if (!_modelReady)
+ return QVariant();
+
+ if (!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount())
+ return QVariant();
+
+ switch (role) {
+ case Qt::ToolTipRole:
+ switch (index.column()) {
+ case 0:
+ return tr("<b>The shortcut for the alias</b><br />"
+ "It can be used as a regular slash command.<br /><br />"
+ "<b>Example:</b> \"foo\" can be used per /foo");
+ case 1:
+ {
+ // To avoid overwhelming the user, organize things into a table
+ QString strTooltip;
+ QTextStream tooltip( &strTooltip, QIODevice::WriteOnly );
+ tooltip << "<qt><style>.bold { font-weight: bold; } .italic { font-style: italic; }</style>";
+
+ // Function to add a row to the tooltip table
+ auto addRow = [&](
+ const QString& key, const QString& value = QString(), bool condition = true) {
+ if (condition) {
+ if (value.isEmpty()) {
+ tooltip << "<tr><td class='italic' align='left' colspan='2'>"
+ << key << "</td></tr>";
+ } else {
+ tooltip << "<tr><td class='bold' align='left'>"
+ << key << "</td><td>" << value << "</td></tr>";
+ }
+ }
+ };
+
+ tooltip << "<p class='bold'>"
+ << tr("The string the shortcut will be expanded to") << "</p>";
+
+ tooltip << "<p class='bold' align='center'>"
+ << tr("Special variables") << "</p>";
+
+ // Variable option table
+ tooltip << "<table cellspacing='5' cellpadding='0'>";
+
+ // Parameter variables
+ addRow(tr("Parameter variables"));
+ addRow("$i", tr("i'th parameter"));
+ addRow("$i..j", tr("i'th to j'th parameter separated by spaces"));
+ addRow("$i..", tr("all parameters from i on separated by spaces"));
+
+ // IrcUser handling
+ addRow(tr("Nickname parameter variables"));
+ addRow("$i:account",
+ tr("account of user identified by i'th parameter, or a '*' if logged out or "
+ "unknown"));
+ addRow("$i:hostname",
+ tr("hostname of user identified by i'th parameter, or a '*' if unknown"));
+ addRow("$i:ident",
+ tr("ident of user identified by i'th parameter, or a '*' if unknown"));
+ addRow("$i:identd",
+ tr("ident of user identified by i'th parameter if verified, or a '*' if unknown "
+ "or unverified (prefixed with '~')"));
+
+ // General variables
+ addRow(tr("General variables"));
+ addRow("$0", tr("the whole string"));
+ addRow("$nick", tr("your current nickname"));
+ addRow("$channel", tr("the name of the selected channel"));
+
+ // End table
+ tooltip << "</table>";
+
+ // Example header
+ tooltip << "<p>"
+ << tr("Multiple commands can be separated with semicolons") << "</p>";
+ // Example
+ tooltip << "<p>";
+ tooltip << QString("<p><span class='bold'>%1</span> %2<br />").arg(
+ tr("Example:"), tr("\"Test $1; Test $2; Test All $0\""));
+ tooltip << tr("...will be expanded to three separate messages \"Test 1\", \"Test 2\" "
+ "and \"Test All 1 2 3\" when called like <i>/test 1 2 3</i>")
+ << "</p>";
+
+ // End tooltip
+ tooltip << "</qt>";
+ return strTooltip;
+ }
+ default:
+ return QVariant();
+ }
+ case Qt::DisplayRole:
+ case Qt::EditRole:
+ switch (index.column()) {
+ case 0:
+ return aliasManager()[index.row()].name;
+ case 1:
+ return aliasManager()[index.row()].expansion;
+ default:
+ return QVariant();
+ }
+ default:
+ return QVariant();
+ }