Commit 03814cda authored by Peter Simonsson's avatar Peter Simonsson

Add date marker for first line on new date if date not in timestamp

parent b73cd701
......@@ -11,11 +11,20 @@ the Free Software Foundation; either version 2 of the License, or
<x>0</x>
<y>0</y>
<width>401</width>
<height>502</height>
<height>558</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
......@@ -27,10 +36,10 @@ the Free Software Foundation; either version 2 of the License, or
<bool>true</bool>
</property>
<layout class="QGridLayout">
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="kcfg_ShowDate">
<property name="text">
<string>Sho&amp;w dates</string>
<item row="0" column="1">
<widget class="KComboBox" name="kcfg_TimestampFormat">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
......@@ -47,10 +56,10 @@ the Free Software Foundation; either version 2 of the License, or
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KComboBox" name="kcfg_TimestampFormat">
<property name="editable">
<bool>true</bool>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="kcfg_ShowDate">
<property name="text">
<string>Sho&amp;w dates</string>
</property>
</widget>
</item>
......@@ -70,6 +79,13 @@ the Free Software Foundation; either version 2 of the License, or
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="kcfg_ShowDateLine">
<property name="text">
<string>Show date marker when date changes</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -313,6 +329,7 @@ the Free Software Foundation; either version 2 of the License, or
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KComboBox</class>
......@@ -350,12 +367,12 @@ the Free Software Foundation; either version 2 of the License, or
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
<x>32</x>
<y>313</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
<x>55</x>
<y>338</y>
</hint>
</hints>
</connection>
......@@ -366,12 +383,12 @@ the Free Software Foundation; either version 2 of the License, or
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
<x>32</x>
<y>313</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
<x>90</x>
<y>413</y>
</hint>
</hints>
</connection>
......@@ -382,12 +399,28 @@ the Free Software Foundation; either version 2 of the License, or
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
<x>32</x>
<y>313</y>
</hint>
<hint type="destinationlabel">
<x>55</x>
<y>364</y>
</hint>
</hints>
</connection>
<connection>
<sender>kcfg_ShowDate</sender>
<signal>toggled(bool)</signal>
<receiver>kcfg_ShowDateLine</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>55</x>
<y>78</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
<x>61</x>
<y>104</y>
</hint>
</hints>
</connection>
......
......@@ -70,6 +70,11 @@
<label></label>
<whatsthis></whatsthis>
</entry>
<entry key="ShowDateLine" type="Bool">
<default>false</default>
<label></label>
<whatsthis></whatsthis>
</entry>
<entry key="TimestampFormat" type="String">
<default>hh:mm</default>
<label></label>
......
......@@ -91,7 +91,8 @@ class SelectionPin
};
IRCView::IRCView(QWidget* parent) : QTextBrowser(parent), m_rememberLine(nullptr), m_lastMarkerLine(nullptr), m_rememberLineDirtyBit(false), markerFormatObject(this)
IRCView::IRCView(QWidget* parent) : QTextBrowser(parent), m_rememberLine(nullptr), m_lastMarkerLine(nullptr),
m_rememberLineDirtyBit(false), markerFormatObject(this), m_prevTimestamp(QDateTime::currentDateTime())
{
m_mousePressedOnUrl = false;
m_isOnNick = false;
......@@ -99,6 +100,7 @@ IRCView::IRCView(QWidget* parent) : QTextBrowser(parent), m_rememberLine(nullptr
m_chatWin = nullptr;
m_server = nullptr;
m_fontSizeDelta = 0;
m_showDate = false;
setAcceptDrops(false);
......@@ -115,6 +117,7 @@ IRCView::IRCView(QWidget* parent) : QTextBrowser(parent), m_rememberLine(nullptr
document()->documentLayout()->registerHandler(IRCView::MarkerLine, &markerFormatObject);
document()->documentLayout()->registerHandler(IRCView::RememberLine, &markerFormatObject);
document()->documentLayout()->registerHandler(IRCView::DateLine, &markerFormatObject);
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(anchorClicked(QUrl)));
......@@ -355,6 +358,11 @@ void IrcViewMarkerLine::drawObject(QPainter *painter, const QRectF &r, QTextDocu
// pen.setStyle(Qt::DashDotDotLine);
break;
case IRCView::BlockIsDateMarker:
pen.setColor(Preferences::self()->color(Preferences::Time));
pen.setStyle(Qt::DashLine);
break;
default:
//nice color, eh?
pen.setColor(Qt::cyan);
......@@ -508,10 +516,14 @@ Burr* IRCView::appendLine(IRCView::ObjectFormats type)
cursor.insertText(QString(QChar::ObjectReplacementCharacter), getFormat(type));
QTextBlock block = cursor.block();
Burr *b = new Burr(this, m_lastMarkerLine, block, type == MarkerLine? BlockIsMarker : BlockIsRemember);
Burr *prevBurr = m_lastMarkerLine;
if(type == DateLine)
prevBurr = nullptr;
Burr *b = new Burr(this, prevBurr, block, objectFormatToBlockState(type));
block.setUserData(b);
m_lastMarkerLine = b;
if(type != DateLine)
m_lastMarkerLine = b;
//TODO figure out what this is for
cursor.setPosition(block.position());
......@@ -519,6 +531,26 @@ Burr* IRCView::appendLine(IRCView::ObjectFormats type)
return b;
}
IRCView::BlockStates IRCView::objectFormatToBlockState(ObjectFormats format)
{
BlockStates state;
switch(format)
{
case MarkerLine:
state = BlockIsMarker;
break;
case RememberLine:
state = BlockIsRemember;
break;
case DateLine:
state = BlockIsDateMarker;
break;
}
return state;
}
// Other stuff
void IRCView::updateAppearance()
......@@ -899,6 +931,14 @@ void IRCView::doAppend(const QString& newLine, bool rtl, bool self)
document()->setMaximumBlockCount(atBottom ? scrollMax : document()->maximumBlockCount() + 1);
}
if (m_showDate)
{
QString timeColor = Preferences::self()->color(Preferences::Time).name();
doRawAppend(QString("<font color=\"%1\">%2</font>").arg(timeColor, QLocale().toString(m_prevTimestamp.date(), QLocale::ShortFormat)), rtl);
appendLine(DateLine);
m_showDate = false;
}
doRawAppend(newLine, rtl);
//FIXME: Disable auto-text for DCC Chats since we don't have a server to parse wildcards.
......@@ -945,7 +985,7 @@ QString IRCView::timeStamp(QHash<QString, QString> messageTags, bool rtl)
if (messageTags.contains(QLatin1String("time"))) // If it exists use the supplied server time.
serverTime = QDateTime::fromString(messageTags[QStringLiteral("time")], Qt::ISODate).toLocalTime();
QTime time = serverTime.isValid() ? serverTime.time() : QTime::currentTime();
QDateTime dateTime = serverTime.isValid() ? serverTime : QDateTime::currentDateTime();
QString timeColor = Preferences::self()->color(Preferences::Time).name();
QString timeFormat = Preferences::self()->timestampFormat();
QString timeString;
......@@ -954,19 +994,20 @@ QString IRCView::timeStamp(QHash<QString, QString> messageTags, bool rtl)
if(!Preferences::self()->showDate())
{
timeString = QString(QLatin1String("<font color=\"") + timeColor + QLatin1String("\">[%1]</font> ")).arg(time.toString(timeFormat));
timeString = QString(QLatin1String("<font color=\"") + timeColor + QLatin1String("\">[%1]</font> ")).arg(dateTime.time().toString(timeFormat));
m_showDate = Preferences::self()->showDateLine() && dateTime.date() != m_prevTimestamp.date();
}
else
{
QDate date = serverTime.isValid() ? serverTime.date() : QDate::currentDate();
timeString = QString("<font color=\"" +
timeColor + "\">[%1%2 %3%4]</font> ")
.arg((dateRtl==rtl) ? QString() : (dateRtl ? RLM : LRM),
QLocale().toString(date, QLocale::ShortFormat),
time.toString(timeFormat),
QLocale().toString(dateTime.date(), QLocale::ShortFormat),
dateTime.time().toString(timeFormat),
(dateRtl==rtl) ? QString() : (!dateRtl ? RLM : LRM));
}
m_prevTimestamp = dateTime;
return timeString;
}
......
......@@ -22,6 +22,7 @@
#include <QTextBrowser>
#include <QUrl>
#include <QDateTime>
class Server;
......@@ -102,10 +103,10 @@ class IRCView : public QTextBrowser
bool hasLines();
/// QTextBlockFormat states for setUserState.
enum BlockStates { None = -1, BlockIsMarker = 1, BlockIsRemember = 2 };
enum BlockStates { None = -1, BlockIsMarker = 1, BlockIsRemember = 2, BlockIsDateMarker = 3 };
/// QTextCharFormat object types.
enum ObjectFormats { MarkerLine = QTextFormat::UserObject, RememberLine};
enum ObjectFormats { MarkerLine = QTextFormat::UserObject, RememberLine, DateLine };
public Q_SLOTS:
/// Inserts a marker line.
......@@ -152,6 +153,8 @@ class IRCView : public QTextBrowser
/// Shortcut to get an object format of the desired type
QTextCharFormat getFormat(ObjectFormats);
BlockStates objectFormatToBlockState(ObjectFormats format);
public Q_SLOTS:
// Doesn't have to be a slot, but what the hay.
/// Called *only* from ~Burr(), by QTextBlockData::free
......@@ -344,5 +347,8 @@ class IRCView : public QTextBrowser
ChatWindow* m_chatWin;
friend class IRCStyleSheet;
QDateTime m_prevTimestamp;
bool m_showDate;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment