forked from blue/squawk
some thoughts about fonts, lastInteraction and label into keyDelegate
This commit is contained in:
parent
2aed8a1209
commit
15fb4bbd62
15 changed files with 166 additions and 171 deletions
|
@ -24,29 +24,40 @@
|
|||
#include <QAbstractItemView>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QTextBlock>
|
||||
#include <QFontDatabase>
|
||||
#include <cmath>
|
||||
|
||||
#include "messagedelegate.h"
|
||||
#include "messagefeed.h"
|
||||
|
||||
int MessageDelegate::avatarHeight(50);
|
||||
int MessageDelegate::margin(6);
|
||||
QFont getFont (QFontDatabase::SystemFont type, bool bold, bool italic) {
|
||||
QFont font = QFontDatabase::systemFont(type);
|
||||
if (bold)
|
||||
font.setBold(true);
|
||||
if (italic)
|
||||
font.setItalic(true);
|
||||
|
||||
return font;
|
||||
}
|
||||
constexpr int textMargin = 2;
|
||||
constexpr int statusIconSize = 16;
|
||||
constexpr float nickFontMultiplier = 1.1;
|
||||
constexpr float dateFontMultiplier = 0.8;
|
||||
|
||||
constexpr int bubbleMargin = 6;
|
||||
constexpr int bubbleBorderRadius = 3;
|
||||
|
||||
int MessageDelegate::avatarHeight(50);
|
||||
int MessageDelegate::margin(6);
|
||||
|
||||
bool MessageDelegate::fontsInitialized(false);
|
||||
QFont MessageDelegate::bodyFont;
|
||||
QFont MessageDelegate::nickFont;
|
||||
QFont MessageDelegate::dateFont;
|
||||
QFontMetrics MessageDelegate::nickMetrics(nickFont);
|
||||
QFontMetrics MessageDelegate::dateMetrics(dateFont);
|
||||
|
||||
MessageDelegate::MessageDelegate(QObject* parent):
|
||||
QStyledItemDelegate(parent),
|
||||
bodyFont(),
|
||||
nickFont(),
|
||||
dateFont(),
|
||||
bodyRenderer(new QTextDocument()),
|
||||
nickMetrics(nickFont),
|
||||
dateMetrics(dateFont),
|
||||
buttonHeight(0),
|
||||
buttonWidth(0),
|
||||
barHeight(0),
|
||||
|
@ -60,7 +71,13 @@ MessageDelegate::MessageDelegate(QObject* parent):
|
|||
currentId(""),
|
||||
selection(0, 0)
|
||||
{
|
||||
if (!fontsInitialized) {
|
||||
fontsInitialized = true;
|
||||
initializeFonts();
|
||||
}
|
||||
|
||||
bodyRenderer->setDocumentMargin(0);
|
||||
bodyRenderer->setDefaultFont(bodyFont);
|
||||
|
||||
QPushButton btn(QCoreApplication::translate("MessageLine", "Download"));
|
||||
buttonHeight = btn.sizeHint().height();
|
||||
|
@ -285,7 +302,6 @@ bool MessageDelegate::needToDrawSender(const QModelIndex& index, const Models::F
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QRect messageRect = option.rect.adjusted(bubbleMargin, margin / 2 + bubbleMargin, -(avatarHeight + 3 * margin + bubbleMargin), -(margin + bubbleMargin) / 2);
|
||||
|
@ -538,38 +554,6 @@ QString MessageDelegate::clearSelection()
|
|||
return lastSelectedId;
|
||||
}
|
||||
|
||||
void MessageDelegate::initializeFonts(const QFont& font)
|
||||
{
|
||||
bodyFont = font;
|
||||
nickFont = font;
|
||||
dateFont = font;
|
||||
|
||||
nickFont.setBold(true);
|
||||
|
||||
float ndps = nickFont.pointSizeF();
|
||||
if (ndps != -1) {
|
||||
nickFont.setPointSizeF(ndps * nickFontMultiplier);
|
||||
} else {
|
||||
nickFont.setPointSize(nickFont.pointSize() * nickFontMultiplier);
|
||||
}
|
||||
|
||||
dateFont.setItalic(true);
|
||||
float dps = dateFont.pointSizeF();
|
||||
if (dps != -1) {
|
||||
dateFont.setPointSizeF(dps * dateFontMultiplier);
|
||||
} else {
|
||||
dateFont.setPointSize(dateFont.pointSize() * dateFontMultiplier);
|
||||
}
|
||||
|
||||
bodyFont.setKerning(false);
|
||||
nickMetrics = QFontMetrics(nickFont);
|
||||
dateMetrics = QFontMetrics(dateFont);
|
||||
|
||||
bodyRenderer->setDefaultFont(bodyFont);
|
||||
|
||||
Preview::initializeFont(bodyFont);
|
||||
}
|
||||
|
||||
bool MessageDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
|
||||
{
|
||||
//qDebug() << event->type();
|
||||
|
@ -828,3 +812,11 @@ void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDelegate::initializeFonts () {
|
||||
bodyFont = getFont(QFontDatabase::GeneralFont, false, false);
|
||||
nickFont = getFont(QFontDatabase::TitleFont, true, false);
|
||||
dateFont = getFont(QFontDatabase::SmallestReadableFont, false, true);
|
||||
nickMetrics = QFontMetrics(nickFont);
|
||||
dateMetrics = QFontMetrics(dateFont);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue