Skip to content
This repository has been archived by the owner on Aug 26, 2020. It is now read-only.

Commit

Permalink
- Add MessageView highlighting and system linkage.
Browse files Browse the repository at this point in the history
  • Loading branch information
3vi1 committed Apr 7, 2017
1 parent 686bfb9 commit 5fc707e
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 19 deletions.
3 changes: 3 additions & 0 deletions docs/FAQ
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ A: Currently there are only a few:
Mousewheel: Over map it will zoom in/out.
Ctrl+Mousewheel: Rotates map (make sure map has focus first - click it)
Ctrl+F: Shortcut for Find System.
Left-Click: On a system to switch the message view to just messages for that
system. Click on an empty space to switch back to all messages.
Double-Click: On a message in the list to find the related system.

You can also click and drag the map around.

Expand Down
9 changes: 9 additions & 0 deletions docs/RELEASES
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
0.8.0 - Messages in list can now be doubleclicked to find the related system.

Message text is now colorized to highlight the mentioned systems, ships,
and other keywords. A future release will make all of these colors
configurable options.

Message view resizing has been improved to size much better. It will
now show the entire message when set smaller.

0.7.8 - Now remembers which pilots you had enabled between runs.

Changes to option saving: Most options are now saved when the options
Expand Down
62 changes: 51 additions & 11 deletions src/chatitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,72 @@

#include "chatitemdelegate.h"

ChatItemDelegate::ChatItemDelegate(QObject *parent) : QItemDelegate(parent)
#include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QPainter>
#include <QTextDocument>

ChatItemDelegate::ChatItemDelegate(QObject *parent) : QStyledItemDelegate(parent)
{
}

void ChatItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index ) const
{
if (index.column() == 0) {
QItemDelegate::paint(painter, option, index);
return;
}

/* This is not really used yet.. For future plans
*/
QStyleOptionViewItem options = option;
initStyleOption(&options, index);

painter->save();

QTextDocument doc;
doc.setHtml(options.text);

QTextOption textOption(doc.defaultTextOption());
textOption.setWrapMode(QTextOption::WordWrap);
doc.setDefaultTextOption(textOption);
doc.setTextWidth(options.rect.width() - m_avatarSize.width() - padding.width());

options.text = "";
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);

// shift text right to make icon visible
QSize iconSize = options.icon.actualSize(options.rect.size());
painter->translate(options.rect.left()+iconSize.width(), options.rect.top());
QRect clip(0, 0, options.rect.width()+iconSize.width(), options.rect.height());

painter->setClipRect(clip);
QAbstractTextDocumentLayout::PaintContext ctx;

if (option.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, QColor("white"));

ctx.clip = clip;
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
}

void ChatItemDelegate::setModel(ChatModel* model)
{
m_model = model;
}

QSize ChatItemDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex &index) const
QSize ChatItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex &index) const
{
// Yes. I'm guessing. I welcome a real way to get the right
// text height.
QStyleOptionViewItem options = option;
initStyleOption(&options, index);

QTextDocument doc;
doc.setHtml(options.text);

QTextOption textOption(doc.defaultTextOption());
textOption.setWrapMode(QTextOption::WordWrap);
doc.setDefaultTextOption(textOption);
doc.setTextWidth(options.rect.width() - m_avatarSize.width() - padding.width());

int guess = (m_model->data(index).toString().length() * .2);
return QSize(0, guess + 64);
QSize textSize = QSize(doc.idealWidth() + m_avatarSize.width(), doc.size().height());
return m_avatarSize.height() > doc.size().height() ?
QSize(doc.idealWidth(), m_avatarSize.height() + padding.height()) : textSize;
}
9 changes: 6 additions & 3 deletions src/chatitemdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

#include <QItemDelegate>
#include <QObject>
#include <QStyledItemDelegate>

#include "chatmodel.h"

class ChatItemDelegate : public QItemDelegate
class ChatItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
Expand All @@ -35,13 +36,15 @@ class ChatItemDelegate : public QItemDelegate
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index ) const override;
void setModel(ChatModel* model);
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;

signals:
public slots:

private:
ChatModel* m_model;
ChatModel* m_model;
QSize m_avatarSize = QSize(64,64);
QSize padding = QSize(2,1);
};

#endif // CHATITEMDELEGATE_H
15 changes: 14 additions & 1 deletion src/chatmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ QVariant ChatModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
return "(" + message.logInfo->channel + " @ " +
message.dateTime.toString("hh:mm:ss") + " " + message.sender + ")\n" +
message.text;
message.markedUpText;
break;
}

Expand Down Expand Up @@ -189,3 +189,16 @@ void ChatModel::subsetForString(const QString& string)
endInsertRows();
}
}

MessageInfo ChatModel::getMessageAt(const QModelIndex &index)
{
MessageInfo message;

if (index.isValid())
{
int row = index.row();
message = *visibleItems.at(row);
}

return message;
}
1 change: 1 addition & 0 deletions src/chatmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ChatModel : public QAbstractListModel
void subsetForSystem(const QString &system);
void subsetForString(const QString &string);
void addEntry(const MessageInfo &message);
MessageInfo getMessageAt(const QModelIndex &index);
void truncateTo(int i);

void avatarChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/imp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = imp
TEMPLATE = app

VERSION = 0.7.8
VERSION = 0.8.0
QMAKE_TARGET_COMPANY = EternalDusk
QMAKE_TARGET_DESCRIPTION = Eve Online Intelligence Management Program
QMAKE_TARGET_COPYRIGHT = (c) Copyright 2016-2017 Jesse Litton
Expand Down
2 changes: 1 addition & 1 deletion src/info.ui
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Created by Jesse Litton&lt;br/&gt;&lt;/span&gt;©&lt;span style=&quot; font-size:12pt;&quot;&gt; Copyright 2016-2017&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Icon, logo, miscellaneous sounds, and music&lt;br/&gt;by Lorelei Litton&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;100% Free to use and open source - See COPYING for details.&lt;br/&gt;Developed on Linux.&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;See CREDITS for additional attributions!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;ISK donations to Khasm Kaotiqa will be used to improve this instead of ratting. :)&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;:/graphics/impicon.png&quot; width=&quot;42&quot; height=&quot;42&quot;/&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;span style=&quot; font-size:12pt; font-weight:600;&quot;&gt;Hello Lone Wolf Union!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Created by Jesse Litton&lt;br/&gt;&lt;/span&gt;©&lt;span style=&quot; font-size:12pt;&quot;&gt; Copyright 2016-2017&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Icon, logo, miscellaneous sounds, and music&lt;br/&gt;by Lorelei Litton&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;100% Free to use and open source - See COPYING for details.&lt;br/&gt;Developed on Linux.&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;See CREDITS for additional attributions!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;ISK donations to Khasm Kaotiqa will be used to improve this instead of ratting. :)&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;:/graphics/impicon.png&quot; width=&quot;42&quot; height=&quot;42&quot;/&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;span style=&quot; font-size:12pt; font-weight:600;&quot;&gt;Hello Yulai Federation!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down
8 changes: 8 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,3 +1550,11 @@ void MainWindow::on_action_Always_on_Top_triggered(bool checked)
this->show();
}
}

void MainWindow::on_listView_doubleClicked(const QModelIndex &index)
{
MessageInfo message = chatModel->getMessageAt(index);

if(message.systems.count() > 0)
findLocation(message.systems[0]);
}
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ private slots:
void on_actionReset_Rotation_triggered();
void on_action_Always_on_Top_triggered(bool checked);

void on_listView_doubleClicked(const QModelIndex &index);

private:
void initParsing();
void initThemes();
Expand Down
4 changes: 2 additions & 2 deletions src/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ static const struct Version
{
Version(){}

QString release = "0.7.8"; //VERSION;
QString name = "Still Some Sort of Lycanthropic Hot Topic";
QString release = "0.8.0"; //VERSION;
QString name = "Hermes Wolf";

QString styleHeader1 = "<span style=\" color:#0000ff;\">";
QString styleFooter1 = "</span>";
Expand Down
33 changes: 33 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,33 @@ void Parser::identifyObjects(MessageInfo& messageInfo)
simChat = simChat.simplified();
QStringList words = simChat.split(" ");

messageInfo.markedUpText = "<span style=\"color: #000000\">";

QString previousWord = "";
for (int i = 0; i < words.length(); i++)
{
QString lowerWord = words[i].toLower();
if (ignoreWords.contains(lowerWord) || words[i].length() < 2)
{
// Common word to ignore, skip it and go to next word.
messageInfo.markedUpText += words[i];
}
else if (statusWords.contains(lowerWord))
{
messageInfo.flags.append(MessageFlag::STATUS);
messageInfo.flags.append(MessageFlag::QUERY);

messageInfo.markedUpText += "<span style=\"color: #900090\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
else if (locationWords.contains(lowerWord))
{
messageInfo.flags.append(MessageFlag::LOCATION);

messageInfo.markedUpText += "<span style=\"color: #00FF00\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
else if (clearWords.contains(lowerWord))
{
Expand All @@ -297,11 +308,18 @@ void Parser::identifyObjects(MessageInfo& messageInfo)
// We don't want to clear a system if someone says a gate is clear.
// "> KBP Dital gate clr!"
messageInfo.flags.append(MessageFlag::CLEAR);

messageInfo.markedUpText += "<span style=\"color: #00D000\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
}
else if(ships.contains(lowerWord))
{
theseShips.append(words[i]);
messageInfo.markedUpText += "<span style=\"color: #d03090\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
else
{
Expand All @@ -315,25 +333,40 @@ void Parser::identifyObjects(MessageInfo& messageInfo)
{
// "x-x gate to..."
theseSystems.append(systemName);
messageInfo.markedUpText += "<span style=\"color: #303030\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
else {
// "...at x-x gate"
theseGates.append(systemName);
messageInfo.markedUpText += "<span style=\"color: #303030\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
}
else
{
// System mentioned, not adjacent to word 'gate'
theseSystems.append(systemName);
messageInfo.markedUpText += "<span style=\"color: #0000FF\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
}
else if(lowerWord.length() >= 3)
{
messageInfo.possiblePilots.append(words[i]);
messageInfo.markedUpText += "<span style=\"color: #804000\">";
messageInfo.markedUpText += words[i];
messageInfo.markedUpText += "<span style=\"color: #000000\">";
}
}

previousWord = lowerWord;

if(i < words.length())
messageInfo.markedUpText += " ";
}

messageInfo.systems = theseSystems;
Expand Down
1 change: 1 addition & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct MessageInfo
QString sender;
QDateTime dateTime;
QString text;
QString markedUpText;

QStringList systems;
QStringList gates;
Expand Down

0 comments on commit 5fc707e

Please sign in to comment.