1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Some style fixes

"if(" → "if ("
"for(" → "for ("
"while(" → "while ("
This commit is contained in:
Zetok Zalbavar 2015-03-20 18:38:10 +00:00
parent 9079b334b9
commit f95291af3e
No known key found for this signature in database
GPG Key ID: C953D3880212068A
15 changed files with 193 additions and 193 deletions

View File

@ -27,9 +27,9 @@ ChatLine::ChatLine()
ChatLine::~ChatLine() ChatLine::~ChatLine()
{ {
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
{ {
if(c->scene()) if (c->scene())
c->scene()->removeItem(c); c->scene()->removeItem(c);
delete c; delete c;
@ -40,15 +40,15 @@ void ChatLine::setRow(int idx)
{ {
row = idx; row = idx;
for(int c = 0; c < static_cast<int>(content.size()); ++c) for (int c = 0; c < static_cast<int>(content.size()); ++c)
content[c]->setIndex(row, c); content[c]->setIndex(row, c);
} }
void ChatLine::visibilityChanged(bool visible) void ChatLine::visibilityChanged(bool visible)
{ {
if(isVisible != visible) if (isVisible != visible)
{ {
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
c->visibilityChanged(visible); c->visibilityChanged(visible);
} }
@ -62,7 +62,7 @@ int ChatLine::getRow() const
ChatLineContent *ChatLine::getContent(int col) const ChatLineContent *ChatLine::getContent(int col) const
{ {
if(col < static_cast<int>(content.size()) && col >= 0) if (col < static_cast<int>(content.size()) && col >= 0)
return content[col]; return content[col];
return nullptr; return nullptr;
@ -70,9 +70,9 @@ ChatLineContent *ChatLine::getContent(int col) const
ChatLineContent *ChatLine::getContent(QPointF scenePos) const ChatLineContent *ChatLine::getContent(QPointF scenePos) const
{ {
for(ChatLineContent* c: content) for (ChatLineContent* c: content)
{ {
if(c->sceneBoundingRect().contains(scenePos)) if (c->sceneBoundingRect().contains(scenePos))
return c; return c;
} }
@ -81,37 +81,37 @@ ChatLineContent *ChatLine::getContent(QPointF scenePos) const
void ChatLine::removeFromScene() void ChatLine::removeFromScene()
{ {
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
{ {
if(c->scene()) if (c->scene())
c->scene()->removeItem(c); c->scene()->removeItem(c);
} }
} }
void ChatLine::addToScene(QGraphicsScene *scene) void ChatLine::addToScene(QGraphicsScene *scene)
{ {
if(!scene) if (!scene)
return; return;
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
scene->addItem(c); scene->addItem(c);
} }
void ChatLine::setVisible(bool visible) void ChatLine::setVisible(bool visible)
{ {
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
c->setVisible(visible); c->setVisible(visible);
} }
void ChatLine::selectionCleared() void ChatLine::selectionCleared()
{ {
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
c->selectionCleared(); c->selectionCleared();
} }
void ChatLine::selectionFocusChanged(bool focusIn) void ChatLine::selectionFocusChanged(bool focusIn)
{ {
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
c->selectionFocusChanged(focusIn); c->selectionFocusChanged(focusIn);
} }
@ -125,7 +125,7 @@ void ChatLine::updateBBox()
bbox.setHeight(0); bbox.setHeight(0);
bbox.setWidth(width); bbox.setWidth(width);
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
bbox.setHeight(qMax(c->sceneBoundingRect().top() - bbox.top() + c->sceneBoundingRect().height(), bbox.height())); bbox.setHeight(qMax(c->sceneBoundingRect().top() - bbox.top() + c->sceneBoundingRect().height(), bbox.height()));
} }
@ -136,7 +136,7 @@ QRectF ChatLine::sceneBoundingRect() const
void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt) void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt)
{ {
if(!item) if (!item)
return; return;
format.push_back(fmt); format.push_back(fmt);
@ -145,7 +145,7 @@ void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt)
void ChatLine::replaceContent(int col, ChatLineContent *lineContent) void ChatLine::replaceContent(int col, ChatLineContent *lineContent)
{ {
if(col >= 0 && col < static_cast<int>(content.size()) && lineContent) if (col >= 0 && col < static_cast<int>(content.size()) && lineContent)
{ {
QGraphicsScene* scene = content[col]->scene(); QGraphicsScene* scene = content[col]->scene();
delete content[col]; delete content[col];
@ -153,7 +153,7 @@ void ChatLine::replaceContent(int col, ChatLineContent *lineContent)
content[col] = lineContent; content[col] = lineContent;
lineContent->setIndex(row, col); lineContent->setIndex(row, col);
if(scene) if (scene)
scene->addItem(content[col]); scene->addItem(content[col]);
layout(width, bbox.topLeft()); layout(width, bbox.topLeft());
@ -170,15 +170,15 @@ void ChatLine::layout(qreal w, QPointF scenePos)
qreal fixedWidth = (content.size()-1) * columnSpacing; qreal fixedWidth = (content.size()-1) * columnSpacing;
qreal varWidth = 0.0; // used for normalisation qreal varWidth = 0.0; // used for normalisation
for(int i = 0; i < static_cast<int>(format.size()); ++i) for (int i = 0; i < static_cast<int>(format.size()); ++i)
{ {
if(format[i].policy == ColumnFormat::FixedSize) if (format[i].policy == ColumnFormat::FixedSize)
fixedWidth += format[i].size; fixedWidth += format[i].size;
else else
varWidth += format[i].size; varWidth += format[i].size;
} }
if(varWidth == 0.0) if (varWidth == 0.0)
varWidth = 1.0; varWidth = 1.0;
qreal leftover = qMax(0.0, width - fixedWidth); qreal leftover = qMax(0.0, width - fixedWidth);
@ -188,11 +188,11 @@ void ChatLine::layout(qreal w, QPointF scenePos)
qreal xPos[content.size()]; qreal xPos[content.size()];
for(int i = 0; i < static_cast<int>(content.size()); ++i) for (int i = 0; i < static_cast<int>(content.size()); ++i)
{ {
// calculate the effective width of the current column // calculate the effective width of the current column
qreal width; qreal width;
if(format[i].policy == ColumnFormat::FixedSize) if (format[i].policy == ColumnFormat::FixedSize)
width = format[i].size; width = format[i].size;
else else
width = format[i].size / varWidth * leftover; width = format[i].size / varWidth * leftover;
@ -222,7 +222,7 @@ void ChatLine::layout(qreal w, QPointF scenePos)
maxVOffset = qMax(maxVOffset, content[i]->getAscent()); maxVOffset = qMax(maxVOffset, content[i]->getAscent());
} }
for(int i = 0; i < static_cast<int>(content.size()); ++i) for (int i = 0; i < static_cast<int>(content.size()); ++i)
{ {
// calculate vertical alignment // calculate vertical alignment
// vertical alignment may depend on width, so we do it in a second pass // vertical alignment may depend on width, so we do it in a second pass
@ -238,7 +238,7 @@ void ChatLine::layout(qreal w, QPointF scenePos)
void ChatLine::moveBy(qreal deltaY) void ChatLine::moveBy(qreal deltaY)
{ {
// reposition only // reposition only
for(ChatLineContent* c : content) for (ChatLineContent* c : content)
c->moveBy(0, deltaY); c->moveBy(0, deltaY);
bbox.moveTop(bbox.top() + deltaY); bbox.moveTop(bbox.top() + deltaY);

View File

@ -30,9 +30,9 @@
template<class T> template<class T>
T clamp(T x, T min, T max) T clamp(T x, T min, T max)
{ {
if(x > max) if (x > max)
return max; return max;
if(x < min) if (x < min)
return min; return min;
return x; return x;
} }
@ -110,22 +110,22 @@ ChatLog::ChatLog(QWidget* parent)
ChatLog::~ChatLog() ChatLog::~ChatLog()
{ {
// Remove chatlines from scene // Remove chatlines from scene
for(ChatLine::Ptr l : lines) for (ChatLine::Ptr l : lines)
l->removeFromScene(); l->removeFromScene();
if(busyNotification) if (busyNotification)
busyNotification->removeFromScene(); busyNotification->removeFromScene();
if(typingNotification) if (typingNotification)
typingNotification->removeFromScene(); typingNotification->removeFromScene();
} }
void ChatLog::clearSelection() void ChatLog::clearSelection()
{ {
if(selectionMode == None) if (selectionMode == None)
return; return;
for(int i=selFirstRow; i<=selLastRow; ++i) for (int i=selFirstRow; i<=selLastRow; ++i)
lines[i]->selectionCleared(); lines[i]->selectionCleared();
selFirstRow = -1; selFirstRow = -1;
@ -151,20 +151,20 @@ void ChatLog::updateSceneRect()
void ChatLog::layout(int start, int end, qreal width) void ChatLog::layout(int start, int end, qreal width)
{ {
if(lines.empty()) if (lines.empty())
return; return;
qreal h = 0.0; qreal h = 0.0;
// Line at start-1 is considered to have the correct position. All following lines are // Line at start-1 is considered to have the correct position. All following lines are
// positioned in respect to this line. // positioned in respect to this line.
if(start - 1 >= 0) if (start - 1 >= 0)
h = lines[start - 1]->sceneBoundingRect().bottom() + lineSpacing; h = lines[start - 1]->sceneBoundingRect().bottom() + lineSpacing;
start = clamp<int>(start, 0, lines.size()); start = clamp<int>(start, 0, lines.size());
end = clamp<int>(end + 1, 0, lines.size()); end = clamp<int>(end + 1, 0, lines.size());
for(int i = start; i < end; ++i) for (int i = start; i < end; ++i)
{ {
ChatLine* l = lines[i].get(); ChatLine* l = lines[i].get();
@ -179,15 +179,15 @@ void ChatLog::mousePressEvent(QMouseEvent* ev)
QPointF scenePos = mapToScene(ev->pos()); QPointF scenePos = mapToScene(ev->pos());
if(ev->button() == Qt::LeftButton) if (ev->button() == Qt::LeftButton)
{ {
clickPos = ev->pos(); clickPos = ev->pos();
clearSelection(); clearSelection();
} }
if(ev->button() == Qt::RightButton) if (ev->button() == Qt::RightButton)
{ {
if(!isOverSelection(scenePos)) if (!isOverSelection(scenePos))
clearSelection(); clearSelection();
} }
} }
@ -198,9 +198,9 @@ void ChatLog::mouseReleaseEvent(QMouseEvent* ev)
QPointF scenePos = mapToScene(ev->pos()); QPointF scenePos = mapToScene(ev->pos());
if(ev->button() == Qt::RightButton) if (ev->button() == Qt::RightButton)
{ {
if(!isOverSelection(scenePos)) if (!isOverSelection(scenePos))
clearSelection(); clearSelection();
} }
@ -213,24 +213,24 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
QPointF scenePos = mapToScene(ev->pos()); QPointF scenePos = mapToScene(ev->pos());
if(ev->buttons() & Qt::LeftButton) if (ev->buttons() & Qt::LeftButton)
{ {
//autoscroll //autoscroll
if(ev->pos().y() < 0) if (ev->pos().y() < 0)
selectionScrollDir = Up; selectionScrollDir = Up;
else if(ev->pos().y() > height()) else if (ev->pos().y() > height())
selectionScrollDir = Down; selectionScrollDir = Down;
else else
selectionScrollDir = NoDirection; selectionScrollDir = NoDirection;
//select //select
if(selectionMode == None && (clickPos - ev->pos()).manhattanLength() > QApplication::startDragDistance()) if (selectionMode == None && (clickPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
{ {
QPointF sceneClickPos = mapToScene(clickPos.toPoint()); QPointF sceneClickPos = mapToScene(clickPos.toPoint());
ChatLine::Ptr line = findLineByPosY(scenePos.y()); ChatLine::Ptr line = findLineByPosY(scenePos.y());
ChatLineContent* content = getContentFromPos(sceneClickPos); ChatLineContent* content = getContentFromPos(sceneClickPos);
if(content) if (content)
{ {
selClickedRow = content->getRow(); selClickedRow = content->getRow();
selClickedCol = content->getColumn(); selClickedCol = content->getColumn();
@ -242,10 +242,10 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
selectionMode = Precise; selectionMode = Precise;
// ungrab mouse grabber // ungrab mouse grabber
if(scene->mouseGrabberItem()) if (scene->mouseGrabberItem())
scene->mouseGrabberItem()->ungrabMouse(); scene->mouseGrabberItem()->ungrabMouse();
} }
else if(line.get()) else if (line.get())
{ {
selClickedRow = line->getRow(); selClickedRow = line->getRow();
selFirstRow = selClickedRow; selFirstRow = selClickedRow;
@ -255,37 +255,37 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
} }
} }
if(selectionMode != None) if (selectionMode != None)
{ {
ChatLineContent* content = getContentFromPos(scenePos); ChatLineContent* content = getContentFromPos(scenePos);
ChatLine::Ptr line = findLineByPosY(scenePos.y()); ChatLine::Ptr line = findLineByPosY(scenePos.y());
int row; int row;
if(content) if (content)
{ {
row = content->getRow(); row = content->getRow();
int col = content->getColumn(); int col = content->getColumn();
if(row == selClickedRow && col == selClickedCol) if (row == selClickedRow && col == selClickedCol)
{ {
selectionMode = Precise; selectionMode = Precise;
content->selectionMouseMove(scenePos); content->selectionMouseMove(scenePos);
selGraphItem->hide(); selGraphItem->hide();
} }
else if(col != selClickedCol) else if (col != selClickedCol)
{ {
selectionMode = Multi; selectionMode = Multi;
lines[selClickedRow]->selectionCleared(); lines[selClickedRow]->selectionCleared();
} }
} }
else if(line.get()) else if (line.get())
{ {
row = line->getRow(); row = line->getRow();
if(row != selClickedRow) if (row != selClickedRow)
{ {
selectionMode = Multi; selectionMode = Multi;
@ -296,10 +296,10 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
else else
return; return;
if(row >= selClickedRow) if (row >= selClickedRow)
selLastRow = row; selLastRow = row;
if(row <= selClickedRow) if (row <= selClickedRow)
selFirstRow = row; selFirstRow = row;
updateMultiSelectionRect(); updateMultiSelectionRect();
@ -312,13 +312,13 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
//Much faster than QGraphicsScene::itemAt()! //Much faster than QGraphicsScene::itemAt()!
ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
{ {
if(lines.empty()) if (lines.empty())
return nullptr; return nullptr;
auto itr = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), ChatLine::lessThanBSRectBottom); auto itr = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), ChatLine::lessThanBSRectBottom);
//find content //find content
if(itr != lines.cend() && (*itr)->sceneBoundingRect().contains(scenePos)) if (itr != lines.cend() && (*itr)->sceneBoundingRect().contains(scenePos))
return (*itr)->getContent(scenePos); return (*itr)->getContent(scenePos);
return nullptr; return nullptr;
@ -326,16 +326,16 @@ ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
bool ChatLog::isOverSelection(QPointF scenePos) const bool ChatLog::isOverSelection(QPointF scenePos) const
{ {
if(selectionMode == Precise) if (selectionMode == Precise)
{ {
ChatLineContent* content = getContentFromPos(scenePos); ChatLineContent* content = getContentFromPos(scenePos);
if(content) if (content)
return content->isOverSelection(scenePos); return content->isOverSelection(scenePos);
} }
else if(selectionMode == Multi) else if (selectionMode == Multi)
{ {
if(selGraphItem->rect().contains(scenePos)) if (selGraphItem->rect().contains(scenePos))
return true; return true;
} }
@ -349,13 +349,13 @@ qreal ChatLog::useableWidth() const
void ChatLog::reposition(int start, int end, qreal deltaY) void ChatLog::reposition(int start, int end, qreal deltaY)
{ {
if(lines.isEmpty()) if (lines.isEmpty())
return; return;
start = clamp<int>(start, 0, lines.size() - 1); start = clamp<int>(start, 0, lines.size() - 1);
end = clamp<int>(end + 1, 0, lines.size()); end = clamp<int>(end + 1, 0, lines.size());
for(int i = start; i < end; ++i) for (int i = start; i < end; ++i)
{ {
ChatLine* l = lines[i].get(); ChatLine* l = lines[i].get();
l->moveBy(deltaY); l->moveBy(deltaY);
@ -364,7 +364,7 @@ void ChatLog::reposition(int start, int end, qreal deltaY)
void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l) void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
{ {
if(!l.get()) if (!l.get())
return; return;
bool stickToBtm = stickToBottom(); bool stickToBtm = stickToBottom();
@ -378,7 +378,7 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
layout(lines.last()->getRow(), lines.size(), useableWidth()); layout(lines.last()->getRow(), lines.size(), useableWidth());
updateSceneRect(); updateSceneRect();
if(stickToBtm) if (stickToBtm)
scrollToBottom(); scrollToBottom();
checkVisibility(); checkVisibility();
@ -387,7 +387,7 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
void ChatLog::insertChatlineOnTop(ChatLine::Ptr l) void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
{ {
if(!l.get()) if (!l.get())
return; return;
insertChatlineOnTop(QList<ChatLine::Ptr>() << l); insertChatlineOnTop(QList<ChatLine::Ptr>() << l);
@ -395,7 +395,7 @@ void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
void ChatLog::insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines) void ChatLog::insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines)
{ {
if(newLines.isEmpty()) if (newLines.isEmpty())
return; return;
QGraphicsScene::ItemIndexMethod oldIndexMeth = scene->itemIndexMethod(); QGraphicsScene::ItemIndexMethod oldIndexMeth = scene->itemIndexMethod();
@ -407,7 +407,7 @@ void ChatLog::insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines)
// add the new lines // add the new lines
int i = 0; int i = 0;
for(ChatLine::Ptr l : newLines) for (ChatLine::Ptr l : newLines)
{ {
l->addToScene(scene); l->addToScene(scene);
l->visibilityChanged(false); l->visibilityChanged(false);
@ -416,7 +416,7 @@ void ChatLog::insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines)
} }
// add the old lines // add the old lines
for(ChatLine::Ptr l : lines) for (ChatLine::Ptr l : lines)
{ {
l->setRow(i++); l->setRow(i++);
combLines.push_back(l); combLines.push_back(l);
@ -443,16 +443,16 @@ void ChatLog::scrollToBottom()
void ChatLog::startResizeWorker() void ChatLog::startResizeWorker()
{ {
if(lines.empty()) if (lines.empty())
return; return;
// (re)start the worker // (re)start the worker
if(!workerTimer->isActive()) if (!workerTimer->isActive())
{ {
// these values must not be reevaluated while the worker is running // these values must not be reevaluated while the worker is running
workerStb = stickToBottom(); workerStb = stickToBottom();
if(!visibleLines.empty()) if (!visibleLines.empty())
workerAnchorLine = visibleLines.first(); workerAnchorLine = visibleLines.first();
} }
@ -480,7 +480,7 @@ void ChatLog::mouseDoubleClickEvent(QMouseEvent *ev)
QPointF scenePos = mapToScene(ev->pos()); QPointF scenePos = mapToScene(ev->pos());
ChatLineContent* content = getContentFromPos(scenePos); ChatLineContent* content = getContentFromPos(scenePos);
if(content) if (content)
{ {
content->selectionDoubleClick(scenePos); content->selectionDoubleClick(scenePos);
selClickedCol = content->getColumn(); selClickedCol = content->getColumn();
@ -495,18 +495,18 @@ void ChatLog::mouseDoubleClickEvent(QMouseEvent *ev)
QString ChatLog::getSelectedText() const QString ChatLog::getSelectedText() const
{ {
if(selectionMode == Precise) if (selectionMode == Precise)
{ {
return lines[selClickedRow]->content[selClickedCol]->getSelectedText(); return lines[selClickedRow]->content[selClickedCol]->getSelectedText();
} }
else if(selectionMode == Multi) else if (selectionMode == Multi)
{ {
// build a nicely formatted message // build a nicely formatted message
QString out; QString out;
for(int i=selFirstRow; i<=selLastRow; ++i) for (int i=selFirstRow; i<=selLastRow; ++i)
{ {
if(lines[i]->content[1]->getText().isEmpty()) if (lines[i]->content[1]->getText().isEmpty())
continue; continue;
QString timestamp = lines[i]->content[2]->getText().isEmpty() ? tr("pending") : lines[i]->content[2]->getText(); QString timestamp = lines[i]->content[2]->getText().isEmpty() ? tr("pending") : lines[i]->content[2]->getText();
@ -546,7 +546,7 @@ void ChatLog::clear()
{ {
clearSelection(); clearSelection();
for(ChatLine::Ptr l : lines) for (ChatLine::Ptr l : lines)
l->removeFromScene(); l->removeFromScene();
lines.clear(); lines.clear();
@ -560,13 +560,13 @@ void ChatLog::copySelectedText(bool toSelectionBuffer) const
QString text = getSelectedText(); QString text = getSelectedText();
QClipboard* clipboard = QApplication::clipboard(); QClipboard* clipboard = QApplication::clipboard();
if(clipboard && !text.isNull()) if (clipboard && !text.isNull())
clipboard->setText(text, toSelectionBuffer ? QClipboard::Selection : QClipboard::Clipboard); clipboard->setText(text, toSelectionBuffer ? QClipboard::Selection : QClipboard::Clipboard);
} }
void ChatLog::setBusyNotification(ChatLine::Ptr notification) void ChatLog::setBusyNotification(ChatLine::Ptr notification)
{ {
if(!notification.get()) if (!notification.get())
return; return;
busyNotification = notification; busyNotification = notification;
@ -585,7 +585,7 @@ void ChatLog::setTypingNotification(ChatLine::Ptr notification)
void ChatLog::setTypingNotificationVisible(bool visible) void ChatLog::setTypingNotificationVisible(bool visible)
{ {
if(typingNotification.get()) if (typingNotification.get())
{ {
typingNotification->setVisible(visible); typingNotification->setVisible(visible);
updateTypingNotification(); updateTypingNotification();
@ -594,7 +594,7 @@ void ChatLog::setTypingNotificationVisible(bool visible)
void ChatLog::scrollToLine(ChatLine::Ptr line) void ChatLog::scrollToLine(ChatLine::Ptr line)
{ {
if(!line.get()) if (!line.get())
return; return;
updateSceneRect(); updateSceneRect();
@ -603,7 +603,7 @@ void ChatLog::scrollToLine(ChatLine::Ptr line)
void ChatLog::selectAll() void ChatLog::selectAll()
{ {
if(lines.empty()) if (lines.empty())
return; return;
clearSelection(); clearSelection();
@ -623,7 +623,7 @@ void ChatLog::forceRelayout()
void ChatLog::checkVisibility() void ChatLog::checkVisibility()
{ {
if(lines.empty()) if (lines.empty())
return; return;
// find first visible line // find first visible line
@ -634,18 +634,18 @@ void ChatLog::checkVisibility()
// set visibilty // set visibilty
QList<ChatLine::Ptr> newVisibleLines; QList<ChatLine::Ptr> newVisibleLines;
for(auto itr = lowerBound; itr != upperBound; ++itr) for (auto itr = lowerBound; itr != upperBound; ++itr)
{ {
newVisibleLines.append(*itr); newVisibleLines.append(*itr);
if(!visibleLines.contains(*itr)) if (!visibleLines.contains(*itr))
(*itr)->visibilityChanged(true); (*itr)->visibilityChanged(true);
visibleLines.removeOne(*itr); visibleLines.removeOne(*itr);
} }
// these lines are no longer visible // these lines are no longer visible
for(ChatLine::Ptr line : visibleLines) for (ChatLine::Ptr line : visibleLines)
line->visibilityChanged(false); line->visibilityChanged(false);
visibleLines = newVisibleLines; visibleLines = newVisibleLines;
@ -653,7 +653,7 @@ void ChatLog::checkVisibility()
// enforce order // enforce order
std::sort(visibleLines.begin(), visibleLines.end(), ChatLine::lessThanRowIndex); std::sort(visibleLines.begin(), visibleLines.end(), ChatLine::lessThanRowIndex);
//if(!visibleLines.empty()) //if (!visibleLines.empty())
// qDebug() << "visible from " << visibleLines.first()->getRow() << "to " << visibleLines.last()->getRow() << " total " << visibleLines.size(); // qDebug() << "visible from " << visibleLines.first()->getRow() << "to " << visibleLines.last()->getRow() << " total " << visibleLines.size();
} }
@ -667,7 +667,7 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
{ {
bool stb = stickToBottom(); bool stb = stickToBottom();
if(ev->size().width() != ev->oldSize().width()) if (ev->size().width() != ev->oldSize().width())
{ {
startResizeWorker(); startResizeWorker();
stb = false; // let the resize worker handle it stb = false; // let the resize worker handle it
@ -675,7 +675,7 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
QGraphicsView::resizeEvent(ev); QGraphicsView::resizeEvent(ev);
if(stb) if (stb)
scrollToBottom(); scrollToBottom();
updateBusyNotification(); updateBusyNotification();
@ -683,13 +683,13 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
void ChatLog::updateMultiSelectionRect() void ChatLog::updateMultiSelectionRect()
{ {
if(selectionMode == Multi && selFirstRow >= 0 && selLastRow >= 0) if (selectionMode == Multi && selFirstRow >= 0 && selLastRow >= 0)
{ {
QRectF selBBox; QRectF selBBox;
selBBox = selBBox.united(lines[selFirstRow]->sceneBoundingRect()); selBBox = selBBox.united(lines[selFirstRow]->sceneBoundingRect());
selBBox = selBBox.united(lines[selLastRow]->sceneBoundingRect()); selBBox = selBBox.united(lines[selLastRow]->sceneBoundingRect());
if(selGraphItem->rect() != selBBox) if (selGraphItem->rect() != selBBox)
scene->invalidate(selGraphItem->rect()); scene->invalidate(selGraphItem->rect());
selGraphItem->setRect(selBBox); selGraphItem->setRect(selBBox);
@ -704,12 +704,12 @@ void ChatLog::updateMultiSelectionRect()
void ChatLog::updateTypingNotification() void ChatLog::updateTypingNotification()
{ {
ChatLine* notification = typingNotification.get(); ChatLine* notification = typingNotification.get();
if(!notification) if (!notification)
return; return;
qreal posY = 0.0; qreal posY = 0.0;
if(!lines.empty()) if (!lines.empty())
posY = lines.last()->sceneBoundingRect().bottom() + lineSpacing; posY = lines.last()->sceneBoundingRect().bottom() + lineSpacing;
notification->layout(useableWidth(), QPointF(0.0, posY)); notification->layout(useableWidth(), QPointF(0.0, posY));
@ -717,7 +717,7 @@ void ChatLog::updateTypingNotification()
void ChatLog::updateBusyNotification() void ChatLog::updateBusyNotification()
{ {
if(busyNotification.get()) if (busyNotification.get())
{ {
//repoisition the busy notification (centered) //repoisition the busy notification (centered)
busyNotification->layout(useableWidth(), getVisibleRect().topLeft() + QPointF(0, getVisibleRect().height()/2.0)); busyNotification->layout(useableWidth(), getVisibleRect().topLeft() + QPointF(0, getVisibleRect().height()/2.0));
@ -728,7 +728,7 @@ ChatLine::Ptr ChatLog::findLineByPosY(qreal yPos) const
{ {
auto itr = std::lower_bound(lines.cbegin(), lines.cend(), yPos, ChatLine::lessThanBSRectBottom); auto itr = std::lower_bound(lines.cbegin(), lines.cend(), yPos, ChatLine::lessThanBSRectBottom);
if(itr != lines.cend()) if (itr != lines.cend())
return *itr; return *itr;
return ChatLine::Ptr(); return ChatLine::Ptr();
@ -738,7 +738,7 @@ QRectF ChatLog::calculateSceneRect() const
{ {
qreal bottom = (lines.empty() ? 0.0 : lines.last()->sceneBoundingRect().bottom()); qreal bottom = (lines.empty() ? 0.0 : lines.last()->sceneBoundingRect().bottom());
if(typingNotification.get() != nullptr) if (typingNotification.get() != nullptr)
bottom += typingNotification->sceneBoundingRect().height() + lineSpacing; bottom += typingNotification->sceneBoundingRect().height() + lineSpacing;
return QRectF(-margins.left(), -margins.top(), useableWidth(), bottom + margins.bottom() + margins.top()); return QRectF(-margins.left(), -margins.top(), useableWidth(), bottom + margins.bottom() + margins.top());
@ -771,7 +771,7 @@ void ChatLog::onWorkerTimeout()
workerLastIndex += stepSize; workerLastIndex += stepSize;
// done? // done?
if(workerLastIndex >= lines.size()) if (workerLastIndex >= lines.size())
{ {
workerTimer->stop(); workerTimer->stop();
@ -785,7 +785,7 @@ void ChatLog::onWorkerTimeout()
updateMultiSelectionRect(); updateMultiSelectionRect();
// scroll // scroll
if(workerStb) if (workerStb)
scrollToBottom(); scrollToBottom();
else else
scrollToLine(workerAnchorLine); scrollToLine(workerAnchorLine);
@ -809,11 +809,11 @@ void ChatLog::focusInEvent(QFocusEvent* ev)
{ {
QGraphicsView::focusInEvent(ev); QGraphicsView::focusInEvent(ev);
if(selectionMode != None) if (selectionMode != None)
{ {
selGraphItem->setBrush(QBrush(selectionRectColor)); selGraphItem->setBrush(QBrush(selectionRectColor));
for(int i=selFirstRow; i<=selLastRow; ++i) for (int i=selFirstRow; i<=selLastRow; ++i)
lines[i]->selectionFocusChanged(true); lines[i]->selectionFocusChanged(true);
} }
} }
@ -822,11 +822,11 @@ void ChatLog::focusOutEvent(QFocusEvent* ev)
{ {
QGraphicsView::focusOutEvent(ev); QGraphicsView::focusOutEvent(ev);
if(selectionMode != None) if (selectionMode != None)
{ {
selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120))); selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120)));
for(int i=selFirstRow; i<=selLastRow; ++i) for (int i=selFirstRow; i<=selLastRow; ++i)
lines[i]->selectionFocusChanged(false); lines[i]->selectionFocusChanged(false);
} }
} }

View File

@ -45,7 +45,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt
const QColor actionColor = QColor("#1818FF"); // has to match the color in innerStyle.css (div.action) const QColor actionColor = QColor("#1818FF"); // has to match the color in innerStyle.css (div.action)
//smileys //smileys
if(Settings::getInstance().getUseEmoticons()) if (Settings::getInstance().getUseEmoticons())
text = SmileyPack::getInstance().smileyfied(text); text = SmileyPack::getInstance().smileyfied(text);
//quotes (green text) //quotes (green text)
@ -70,7 +70,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt
msg->addColumn(new Text(text, Style::getFont(Style::Big), false, type == ACTION ? QString("*%1 %2*").arg(sender, rawMessage) : rawMessage), ColumnFormat(1.0, ColumnFormat::VariableSize)); msg->addColumn(new Text(text, Style::getFont(Style::Big), false, type == ACTION ? QString("*%1 %2*").arg(sender, rawMessage) : rawMessage), ColumnFormat(1.0, ColumnFormat::VariableSize));
msg->addColumn(new Spinner(":/ui/chatArea/spinner.svg", QSize(16, 16), 360.0/1.6), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right)); msg->addColumn(new Spinner(":/ui/chatArea/spinner.svg", QSize(16, 16), 360.0/1.6), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
if(!date.isNull()) if (!date.isNull())
msg->markAsSent(date); msg->markAsSent(date);
return msg; return msg;
@ -137,7 +137,7 @@ void ChatMessage::markAsSent(const QDateTime &time)
QString ChatMessage::toString() const QString ChatMessage::toString() const
{ {
ChatLineContent* c = getContent(1); ChatLineContent* c = getContent(1);
if(c) if (c)
return c->getText(); return c->getText();
return QString(); return QString();
@ -156,14 +156,14 @@ void ChatMessage::setAsAction()
void ChatMessage::hideSender() void ChatMessage::hideSender()
{ {
ChatLineContent* c = getContent(0); ChatLineContent* c = getContent(0);
if(c) if (c)
c->hide(); c->hide();
} }
void ChatMessage::hideDate() void ChatMessage::hideDate()
{ {
ChatLineContent* c = getContent(2); ChatLineContent* c = getContent(2);
if(c) if (c)
c->hide(); c->hide();
} }

View File

@ -81,7 +81,7 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
setupButtons(); setupButtons();
//preview //preview
if(fileInfo.direction == ToxFile::SENDING) if (fileInfo.direction == ToxFile::SENDING)
{ {
showPreview(fileInfo.filePath); showPreview(fileInfo.filePath);
ui->progressLabel->setText(tr("Waiting to send...", "file transfer widget")); ui->progressLabel->setText(tr("Waiting to send...", "file transfer widget"));
@ -110,7 +110,7 @@ void FileTransferWidget::autoAcceptTransfer(const QString &path)
filepath = QString("%1/%2%3.%4").arg(path, base, number > 0 ? QString(" (%1)").arg(QString::number(number)) : QString(), suffix); filepath = QString("%1/%2%3.%4").arg(path, base, number > 0 ? QString(" (%1)").arg(QString::number(number)) : QString(), suffix);
number++; number++;
} }
while(QFileInfo(filepath).exists()); while (QFileInfo(filepath).exists());
//Do not automatically accept the file-transfer if the path is not writable. //Do not automatically accept the file-transfer if the path is not writable.
//The user can still accept it manually. //The user can still accept it manually.
@ -122,11 +122,11 @@ void FileTransferWidget::autoAcceptTransfer(const QString &path)
void FileTransferWidget::acceptTransfer(const QString &filepath) void FileTransferWidget::acceptTransfer(const QString &filepath)
{ {
if(filepath.isEmpty()) if (filepath.isEmpty())
return; return;
//test if writable //test if writable
if(!Nexus::isFilePathWritable(filepath)) if (!Nexus::isFilePathWritable(filepath))
{ {
QMessageBox::warning(0, QMessageBox::warning(0,
tr("Location not writable","Title of permissions popup"), tr("Location not writable","Title of permissions popup"),
@ -140,7 +140,7 @@ void FileTransferWidget::acceptTransfer(const QString &filepath)
void FileTransferWidget::setBackgroundColor(const QColor &c, bool whiteFont) void FileTransferWidget::setBackgroundColor(const QColor &c, bool whiteFont)
{ {
if(c != backgroundColor) if (c != backgroundColor)
{ {
backgroundColorAnimation->setStartValue(backgroundColor); backgroundColorAnimation->setStartValue(backgroundColor);
backgroundColorAnimation->setEndValue(c); backgroundColorAnimation->setEndValue(c);
@ -157,7 +157,7 @@ void FileTransferWidget::setBackgroundColor(const QColor &c, bool whiteFont)
void FileTransferWidget::setButtonColor(const QColor &c) void FileTransferWidget::setButtonColor(const QColor &c)
{ {
if(c != buttonColor) if (c != buttonColor)
{ {
buttonColorAnimation->setStartValue(buttonColor); buttonColorAnimation->setStartValue(buttonColor);
buttonColorAnimation->setEndValue(c); buttonColorAnimation->setEndValue(c);
@ -184,12 +184,12 @@ void FileTransferWidget::paintEvent(QPaintEvent *)
const int lineWidth = 1; const int lineWidth = 1;
// draw background // draw background
if(drawButtonAreaNeeded()) if (drawButtonAreaNeeded())
painter.setClipRect(QRect(0,0,width()-buttonFieldWidth,height())); painter.setClipRect(QRect(0,0,width()-buttonFieldWidth,height()));
painter.setBrush(QBrush(backgroundColor)); painter.setBrush(QBrush(backgroundColor));
painter.drawRoundRect(geometry(), r * ratio, r); painter.drawRoundRect(geometry(), r * ratio, r);
if(drawButtonAreaNeeded()) if (drawButtonAreaNeeded())
{ {
// draw button background (top) // draw button background (top)
painter.setBrush(QBrush(buttonColor)); painter.setBrush(QBrush(buttonColor));
@ -208,12 +208,12 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
QTime now = QTime::currentTime(); QTime now = QTime::currentTime();
qint64 dt = lastTick.msecsTo(now); //ms qint64 dt = lastTick.msecsTo(now); //ms
if(fileInfo != file || dt < 1000) if (fileInfo != file || dt < 1000)
return; return;
fileInfo = file; fileInfo = file;
if(fileInfo.status == ToxFile::TRANSMITTING) if (fileInfo.status == ToxFile::TRANSMITTING)
{ {
// update progress // update progress
qreal progress = static_cast<qreal>(file.bytesSent) / static_cast<qreal>(file.filesize); qreal progress = static_cast<qreal>(file.bytesSent) / static_cast<qreal>(file.filesize);
@ -230,13 +230,13 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
meanData[meanIndex++] = bytesPerSec; meanData[meanIndex++] = bytesPerSec;
qreal meanBytesPerSec = 0.0; qreal meanBytesPerSec = 0.0;
for(size_t i = 0; i < TRANSFER_ROLLING_AVG_COUNT; ++i) for (size_t i = 0; i < TRANSFER_ROLLING_AVG_COUNT; ++i)
meanBytesPerSec += meanData[i]; meanBytesPerSec += meanData[i];
meanBytesPerSec /= static_cast<qreal>(TRANSFER_ROLLING_AVG_COUNT); meanBytesPerSec /= static_cast<qreal>(TRANSFER_ROLLING_AVG_COUNT);
// update UI // update UI
if(meanBytesPerSec > 0) if (meanBytesPerSec > 0)
{ {
// ETA // ETA
QTime toGo = QTime(0,0).addSecs((file.filesize - file.bytesSent) / meanBytesPerSec); QTime toGo = QTime(0,0).addSecs((file.filesize - file.bytesSent) / meanBytesPerSec);
@ -261,7 +261,7 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
void FileTransferWidget::onFileTransferAccepted(ToxFile file) void FileTransferWidget::onFileTransferAccepted(ToxFile file)
{ {
if(fileInfo != file) if (fileInfo != file)
return; return;
fileInfo = file; fileInfo = file;
@ -273,7 +273,7 @@ void FileTransferWidget::onFileTransferAccepted(ToxFile file)
void FileTransferWidget::onFileTransferCancelled(ToxFile file) void FileTransferWidget::onFileTransferCancelled(ToxFile file)
{ {
if(fileInfo != file) if (fileInfo != file)
return; return;
fileInfo = file; fileInfo = file;
@ -288,7 +288,7 @@ void FileTransferWidget::onFileTransferCancelled(ToxFile file)
void FileTransferWidget::onFileTransferPaused(ToxFile file) void FileTransferWidget::onFileTransferPaused(ToxFile file)
{ {
if(fileInfo != file) if (fileInfo != file)
return; return;
fileInfo = file; fileInfo = file;
@ -298,7 +298,7 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
// reset mean // reset mean
meanIndex = 0; meanIndex = 0;
for(size_t i=0; i<TRANSFER_ROLLING_AVG_COUNT; ++i) for (size_t i=0; i<TRANSFER_ROLLING_AVG_COUNT; ++i)
meanData[i] = 0.0; meanData[i] = 0.0;
setBackgroundColor(Style::getColor(Style::LightGrey), false); setBackgroundColor(Style::getColor(Style::LightGrey), false);
@ -308,7 +308,7 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
void FileTransferWidget::onFileTransferFinished(ToxFile file) void FileTransferWidget::onFileTransferFinished(ToxFile file)
{ {
if(fileInfo != file) if (fileInfo != file)
return; return;
fileInfo = file; fileInfo = file;
@ -327,7 +327,7 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file)
ui->bottomButton->show(); ui->bottomButton->show();
// preview // preview
if(fileInfo.direction == ToxFile::RECEIVING) if (fileInfo.direction == ToxFile::RECEIVING)
showPreview(fileInfo.filePath); showPreview(fileInfo.filePath);
disconnect(Core::getInstance(), 0, this, 0); disconnect(Core::getInstance(), 0, this, 0);
@ -382,7 +382,7 @@ void FileTransferWidget::setupButtons()
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg")); ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg"));
ui->topButton->setObjectName("cancel"); ui->topButton->setObjectName("cancel");
if(fileInfo.direction == ToxFile::SENDING) if (fileInfo.direction == ToxFile::SENDING)
{ {
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/pause.svg")); ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/pause.svg"));
ui->bottomButton->setObjectName("pause"); ui->bottomButton->setObjectName("pause");
@ -398,31 +398,31 @@ void FileTransferWidget::setupButtons()
void FileTransferWidget::handleButton(QPushButton *btn) void FileTransferWidget::handleButton(QPushButton *btn)
{ {
if(fileInfo.direction == ToxFile::SENDING) if (fileInfo.direction == ToxFile::SENDING)
{ {
if(btn->objectName() == "cancel") if (btn->objectName() == "cancel")
Core::getInstance()->cancelFileSend(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->cancelFileSend(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "pause") else if (btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "resume") else if (btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
} }
else else
{ {
if(btn->objectName() == "cancel") if (btn->objectName() == "cancel")
Core::getInstance()->cancelFileRecv(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->cancelFileRecv(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "pause") else if (btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "resume") else if (btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "accept") else if (btn->objectName() == "accept")
{ {
QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName)); QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName));
acceptTransfer(path); acceptTransfer(path);
} }
} }
if(btn->objectName() == "ok") if (btn->objectName() == "ok")
{ {
Widget::confirmExecutableOpen(QFileInfo(fileInfo.filePath)); Widget::confirmExecutableOpen(QFileInfo(fileInfo.filePath));
} }
@ -438,7 +438,7 @@ void FileTransferWidget::showPreview(const QString &filename)
{ {
static const QStringList previewExtensions = { "png", "jpeg", "jpg", "gif" }; static const QStringList previewExtensions = { "png", "jpeg", "jpg", "gif" };
if(previewExtensions.contains(QFileInfo(filename).suffix())) if (previewExtensions.contains(QFileInfo(filename).suffix()))
{ {
const int size = qMax(ui->previewLabel->width(), ui->previewLabel->height()); const int size = qMax(ui->previewLabel->width(), ui->previewLabel->height());
QPixmap pmap = QPixmap(filename).scaled(QSize(size, size), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); QPixmap pmap = QPixmap(filename).scaled(QSize(size, size), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);

View File

@ -68,7 +68,7 @@ void NotificationIcon::updateGradient()
{ {
alpha += 0.01; alpha += 0.01;
if(alpha + dotWidth >= 1.0) if (alpha + dotWidth >= 1.0)
alpha = 0.0; alpha = 0.0;
grad = QLinearGradient(QPointF(-0.5*size.width(),0), QPointF(3.0/2.0*size.width(),0)); grad = QLinearGradient(QPointF(-0.5*size.width(),0), QPointF(3.0/2.0*size.width(),0));
@ -78,6 +78,6 @@ void NotificationIcon::updateGradient()
grad.setColorAt(qMin(1.0, alpha + dotWidth), Qt::lightGray); grad.setColorAt(qMin(1.0, alpha + dotWidth), Qt::lightGray);
grad.setColorAt(1, Qt::lightGray); grad.setColorAt(1, Qt::lightGray);
if(scene() && isVisible()) if (scene() && isVisible())
scene()->invalidate(sceneBoundingRect()); scene()->invalidate(sceneBoundingRect());
} }

View File

@ -70,7 +70,7 @@ void Spinner::setWidth(qreal width)
void Spinner::visibilityChanged(bool visible) void Spinner::visibilityChanged(bool visible)
{ {
if(visible) if (visible)
timer.start(); timer.start();
else else
timer.stop(); timer.stop();
@ -83,6 +83,6 @@ qreal Spinner::getAscent() const
void Spinner::timeout() void Spinner::timeout()
{ {
if(scene()) if (scene())
scene()->invalidate(sceneBoundingRect()); scene()->invalidate(sceneBoundingRect());
} }

View File

@ -41,7 +41,7 @@ Text::Text(const QString& txt, QFont font, bool enableElide, const QString &rwTe
Text::~Text() Text::~Text()
{ {
if(doc) if (doc)
DocumentCache::getInstance().push(doc); DocumentCache::getInstance().push(doc);
} }
@ -56,7 +56,7 @@ void Text::setWidth(qreal w)
width = w; width = w;
dirty = true; dirty = true;
if(elide) if (elide)
{ {
QFontMetrics metrics = QFontMetrics(defFont); QFontMetrics metrics = QFontMetrics(defFont);
elidedText = metrics.elidedText(text, Qt::ElideRight, width); elidedText = metrics.elidedText(text, Qt::ElideRight, width);
@ -67,11 +67,11 @@ void Text::setWidth(qreal w)
void Text::selectionMouseMove(QPointF scenePos) void Text::selectionMouseMove(QPointF scenePos)
{ {
if(!doc) if (!doc)
return; return;
int cur = cursorFromPos(scenePos); int cur = cursorFromPos(scenePos);
if(cur >= 0) if (cur >= 0)
{ {
selectionEnd = cur; selectionEnd = cur;
selectedText = extractSanitizedText(getSelectionStart(), getSelectionEnd()); selectedText = extractSanitizedText(getSelectionStart(), getSelectionEnd());
@ -83,7 +83,7 @@ void Text::selectionMouseMove(QPointF scenePos)
void Text::selectionStarted(QPointF scenePos) void Text::selectionStarted(QPointF scenePos)
{ {
int cur = cursorFromPos(scenePos); int cur = cursorFromPos(scenePos);
if(cur >= 0) if (cur >= 0)
{ {
selectionEnd = cur; selectionEnd = cur;
selectionAnchor = cur; selectionAnchor = cur;
@ -103,12 +103,12 @@ void Text::selectionCleared()
void Text::selectionDoubleClick(QPointF scenePos) void Text::selectionDoubleClick(QPointF scenePos)
{ {
if(!doc) if (!doc)
return; return;
int cur = cursorFromPos(scenePos); int cur = cursorFromPos(scenePos);
if(cur >= 0) if (cur >= 0)
{ {
QTextCursor cursor(doc); QTextCursor cursor(doc);
cursor.setPosition(cur); cursor.setPosition(cur);
@ -132,7 +132,7 @@ void Text::selectionFocusChanged(bool focusIn)
bool Text::isOverSelection(QPointF scenePos) const bool Text::isOverSelection(QPointF scenePos) const
{ {
int cur = cursorFromPos(scenePos); int cur = cursorFromPos(scenePos);
if(getSelectionStart() < cur && getSelectionEnd() >= cur) if (getSelectionStart() < cur && getSelectionEnd() >= cur)
return true; return true;
return false; return false;
@ -150,7 +150,7 @@ QRectF Text::boundingRect() const
void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{ {
if(doc) if (doc)
{ {
painter->setClipRect(boundingRect()); painter->setClipRect(boundingRect());
@ -158,7 +158,7 @@ void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWid
QAbstractTextDocumentLayout::PaintContext ctx; QAbstractTextDocumentLayout::PaintContext ctx;
QAbstractTextDocumentLayout::Selection sel; QAbstractTextDocumentLayout::Selection sel;
if(hasSelection()) if (hasSelection())
{ {
sel.cursor = QTextCursor(doc); sel.cursor = QTextCursor(doc);
sel.cursor.setPosition(getSelectionStart()); sel.cursor.setPosition(getSelectionStart());
@ -194,30 +194,30 @@ qreal Text::getAscent() const
void Text::mousePressEvent(QGraphicsSceneMouseEvent *event) void Text::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if(event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
event->accept(); // grabber event->accept(); // grabber
} }
void Text::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void Text::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if(!doc) if (!doc)
return; return;
QString anchor = doc->documentLayout()->anchorAt(event->pos()); QString anchor = doc->documentLayout()->anchorAt(event->pos());
// open anchor in browser // open anchor in browser
if(!anchor.isEmpty()) if (!anchor.isEmpty())
QDesktopServices::openUrl(anchor); QDesktopServices::openUrl(anchor);
} }
void Text::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void Text::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{ {
if(!doc) if (!doc)
return; return;
QString anchor = doc->documentLayout()->anchorAt(event->pos()); QString anchor = doc->documentLayout()->anchorAt(event->pos());
if(!anchor.isEmpty()) if (!anchor.isEmpty())
setCursor(QCursor(Qt::PointingHandCursor)); setCursor(QCursor(Qt::PointingHandCursor));
else else
setCursor(QCursor()); setCursor(QCursor());
@ -233,17 +233,17 @@ QString Text::getText() const
void Text::regenerate() void Text::regenerate()
{ {
if(!doc) if (!doc)
{ {
doc = DocumentCache::getInstance().pop(); doc = DocumentCache::getInstance().pop();
dirty = true; dirty = true;
} }
if(dirty) if (dirty)
{ {
doc->setDefaultFont(defFont); doc->setDefaultFont(defFont);
if(!elide) if (!elide)
doc->setHtml(text); doc->setHtml(text);
else else
doc->setPlainText(elidedText); doc->setPlainText(elidedText);
@ -258,11 +258,11 @@ void Text::regenerate()
doc->documentLayout()->update(); doc->documentLayout()->update();
// update ascent // update ascent
if(doc->firstBlock().layout()->lineCount() > 0) if (doc->firstBlock().layout()->lineCount() > 0)
ascent = doc->firstBlock().layout()->lineAt(0).ascent(); ascent = doc->firstBlock().layout()->lineAt(0).ascent();
// let the scene know about our change in size // let the scene know about our change in size
if(size != idealSize()) if (size != idealSize())
prepareGeometryChange(); prepareGeometryChange();
// get the new width and height // get the new width and height
@ -272,7 +272,7 @@ void Text::regenerate()
} }
// if we are not visible -> free mem // if we are not visible -> free mem
if(!keepInMemory) if (!keepInMemory)
freeResources(); freeResources();
} }
@ -284,7 +284,7 @@ void Text::freeResources()
QSizeF Text::idealSize() QSizeF Text::idealSize()
{ {
if(doc) if (doc)
return QSizeF(qMin(doc->idealWidth(), width), doc->size().height()); return QSizeF(qMin(doc->idealWidth(), width), doc->size().height());
return size; return size;
@ -292,7 +292,7 @@ QSizeF Text::idealSize()
int Text::cursorFromPos(QPointF scenePos, bool fuzzy) const int Text::cursorFromPos(QPointF scenePos, bool fuzzy) const
{ {
if(doc) if (doc)
return doc->documentLayout()->hitTest(mapFromScene(scenePos), fuzzy ? Qt::FuzzyHit : Qt::ExactHit); return doc->documentLayout()->hitTest(mapFromScene(scenePos), fuzzy ? Qt::FuzzyHit : Qt::ExactHit);
return -1; return -1;
@ -315,23 +315,23 @@ bool Text::hasSelection() const
QString Text::extractSanitizedText(int from, int to) const QString Text::extractSanitizedText(int from, int to) const
{ {
if(!doc) if (!doc)
return ""; return "";
QString txt; QString txt;
QTextBlock block = doc->firstBlock(); QTextBlock block = doc->firstBlock();
for(QTextBlock::Iterator itr = block.begin(); itr!=block.end(); ++itr) for (QTextBlock::Iterator itr = block.begin(); itr!=block.end(); ++itr)
{ {
int pos = itr.fragment().position(); //fragment position -> position of the first character in the fragment int pos = itr.fragment().position(); //fragment position -> position of the first character in the fragment
if(itr.fragment().charFormat().isImageFormat()) if (itr.fragment().charFormat().isImageFormat())
{ {
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat(); QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
QString key = imgFmt.name(); //img key (eg. key::D for :D) QString key = imgFmt.name(); //img key (eg. key::D for :D)
QString rune = key.mid(4); QString rune = key.mid(4);
if(pos >= from && pos < to) if (pos >= from && pos < to)
{ {
txt += rune; txt += rune;
pos++; pos++;
@ -339,9 +339,9 @@ QString Text::extractSanitizedText(int from, int to) const
} }
else else
{ {
for(QChar c : itr.fragment().text()) for (QChar c : itr.fragment().text())
{ {
if(pos >= from && pos < to) if (pos >= from && pos < to)
txt += c; txt += c;
pos++; pos++;
@ -354,9 +354,9 @@ QString Text::extractSanitizedText(int from, int to) const
QString Text::extractImgTooltip(int pos) const QString Text::extractImgTooltip(int pos) const
{ {
for(QTextBlock::Iterator itr = doc->firstBlock().begin(); itr!=doc->firstBlock().end(); ++itr) for (QTextBlock::Iterator itr = doc->firstBlock().begin(); itr!=doc->firstBlock().end(); ++itr)
{ {
if(itr.fragment().contains(pos) && itr.fragment().charFormat().isImageFormat()) if (itr.fragment().contains(pos) && itr.fragment().charFormat().isImageFormat())
{ {
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat(); QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
return imgFmt.toolTip(); return imgFmt.toolTip();

View File

@ -19,13 +19,13 @@
DocumentCache::~DocumentCache() DocumentCache::~DocumentCache()
{ {
while(!documents.isEmpty()) while (!documents.isEmpty())
delete documents.pop(); delete documents.pop();
} }
QTextDocument* DocumentCache::pop() QTextDocument* DocumentCache::pop()
{ {
if(documents.empty()) if (documents.empty())
documents.push(new CustomTextDocument); documents.push(new CustomTextDocument);
return documents.pop(); return documents.pop();
@ -33,7 +33,7 @@ QTextDocument* DocumentCache::pop()
void DocumentCache::push(QTextDocument *doc) void DocumentCache::push(QTextDocument *doc)
{ {
if(doc) if (doc)
{ {
doc->clear(); doc->clear();
documents.push(doc); documents.push(doc);

View File

@ -20,7 +20,7 @@ QPixmap PixmapCache::get(const QString &filename, QSize size)
{ {
auto itr = cache.find(filename); auto itr = cache.find(filename);
if(itr == cache.end()) if (itr == cache.end())
{ {
QIcon icon; QIcon icon;
icon.addFile(filename); icon.addFile(filename);

View File

@ -136,7 +136,7 @@ bool SmileyPack::load(const QString& filename)
cacheSmiley(file); // preload all smileys cacheSmiley(file); // preload all smileys
if(!getCachedSmiley(emoticon).isNull()) if (!getCachedSmiley(emoticon).isNull())
emoticonSet.push_back(emoticon); emoticonSet.push_back(emoticon);
stringElement = stringElement.nextSibling().toElement(); stringElement = stringElement.nextSibling().toElement();

View File

@ -157,7 +157,7 @@ void CameraWorker::subscribe()
qDebug() << "CameraWorker:" << "OpenCV exception caught: " << e.what(); qDebug() << "CameraWorker:" << "OpenCV exception caught: " << e.what();
} }
if(!bSuccess) if (!bSuccess)
{ {
qDebug() << "CameraWorker: Could not open camera"; qDebug() << "CameraWorker: Could not open camera";
} }

View File

@ -244,11 +244,11 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|| Settings::getInstance().getAutoSaveEnabled()) || Settings::getInstance().getAutoSaveEnabled())
{ {
ChatLineContentProxy* proxy = dynamic_cast<ChatLineContentProxy*>(msg->getContent(1)); ChatLineContentProxy* proxy = dynamic_cast<ChatLineContentProxy*>(msg->getContent(1));
if(proxy) if (proxy)
{ {
FileTransferWidget* tfWidget = dynamic_cast<FileTransferWidget*>(proxy->getWidget()); FileTransferWidget* tfWidget = dynamic_cast<FileTransferWidget*>(proxy->getWidget());
if(tfWidget) if (tfWidget)
tfWidget->autoAcceptTransfer(Settings::getInstance().getAutoAcceptDir(f->getToxID())); tfWidget->autoAcceptTransfer(Settings::getInstance().getAutoAcceptDir(f->getToxID()));
} }
} }
@ -563,7 +563,7 @@ void ChatForm::onHangupCallTriggered()
qDebug() << "onHangupCallTriggered"; qDebug() << "onHangupCallTriggered";
//Fixes an OS X bug with ending a call while in full screen //Fixes an OS X bug with ending a call while in full screen
if(netcam->isFullScreen()) if (netcam->isFullScreen())
{ {
netcam->showNormal(); netcam->showNormal();
} }
@ -663,7 +663,7 @@ void ChatForm::enableCallButtons()
videoButton->setToolTip(""); videoButton->setToolTip("");
videoButton->disconnect(); videoButton->disconnect();
if(disableCallButtonsTimer == nullptr) if (disableCallButtonsTimer == nullptr)
{ {
disableCallButtonsTimer = new QTimer(); disableCallButtonsTimer = new QTimer();
connect(disableCallButtonsTimer, SIGNAL(timeout()), connect(disableCallButtonsTimer, SIGNAL(timeout()),
@ -843,7 +843,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
authorId.isMine(), authorId.isMine(),
QDateTime()); QDateTime());
if(!isAction && prevId == authorId) if (!isAction && prevId == authorId)
msg->hideSender(); msg->hideSender();
prevId = authorId; prevId = authorId;
@ -951,7 +951,7 @@ void ChatForm::setFriendTyping(bool isTyping)
Text* text = dynamic_cast<Text*>(chatWidget->getTypingNotification()->getContent(1)); Text* text = dynamic_cast<Text*>(chatWidget->getTypingNotification()->getContent(1));
if(text) if (text)
text->setText("<div class=typing>" + QString("%1 is typing").arg(f->getDisplayedName()) + "</div>"); text->setText("<div class=typing>" + QString("%1 is typing").arg(f->getDisplayedName()) + "</div>");
} }

View File

@ -225,7 +225,7 @@ ChatMessage::Ptr GenericChatForm::addMessage(const ToxID& author, const QString
QString authorStr = author.isMine() ? Core::getInstance()->getUsername() : resolveToxID(author); QString authorStr = author.isMine() ? Core::getInstance()->getUsername() : resolveToxID(author);
ChatMessage::Ptr msg; ChatMessage::Ptr msg;
if(isAction) if (isAction)
{ {
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, false); msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, false);
previousId.clear(); previousId.clear();
@ -233,7 +233,7 @@ ChatMessage::Ptr GenericChatForm::addMessage(const ToxID& author, const QString
else else
{ {
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, author.isMine()); msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, author.isMine());
if(author == previousId) if (author == previousId)
msg->hideSender(); msg->hideSender();
previousId = author; previousId = author;
@ -241,7 +241,7 @@ ChatMessage::Ptr GenericChatForm::addMessage(const ToxID& author, const QString
insertChatMessage(msg); insertChatMessage(msg);
if(isSent) if (isSent)
msg->markAsSent(datetime); msg->markAsSent(datetime);
return msg; return msg;
@ -258,7 +258,7 @@ void GenericChatForm::addAlertMessage(const ToxID &author, QString message, QDat
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isMine(), datetime); ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isMine(), datetime);
insertChatMessage(msg); insertChatMessage(msg);
if(author == previousId) if (author == previousId)
msg->hideSender(); msg->hideSender();
previousId = author; previousId = author;
@ -303,7 +303,7 @@ void GenericChatForm::onSaveLogClicked()
QString plainText; QString plainText;
auto lines = chatWidget->getLines(); auto lines = chatWidget->getLines();
for(ChatLine::Ptr l : lines) for (ChatLine::Ptr l : lines)
{ {
Timestamp* rightCol = dynamic_cast<Timestamp*>(l->getContent(2)); Timestamp* rightCol = dynamic_cast<Timestamp*>(l->getContent(2));
ChatLineContent* middleCol = l->getContent(1); ChatLineContent* middleCol = l->getContent(1);

View File

@ -131,7 +131,7 @@ void FriendWidget::setAsActiveChatroom()
if (isDefaultAvatar) if (isDefaultAvatar)
avatar->setPixmap(QPixmap(":img/contact_dark.svg"), Qt::transparent); avatar->setPixmap(QPixmap(":img/contact_dark.svg"), Qt::transparent);
if(!historyLoaded) if (!historyLoaded)
{ {
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);
if (Settings::getInstance().getEnableLogging()) if (Settings::getInstance().getEnableLogging())

View File

@ -225,7 +225,7 @@ void Widget::setTranslation()
bool Widget::eventFilter(QObject *obj, QEvent *event) bool Widget::eventFilter(QObject *obj, QEvent *event)
{ {
if(event->type() == QEvent::WindowStateChange && obj != NULL) if (event->type() == QEvent::WindowStateChange && obj != NULL)
{ {
QWindowStateChangeEvent * ce = static_cast<QWindowStateChangeEvent*>(event); QWindowStateChangeEvent * ce = static_cast<QWindowStateChangeEvent*>(event);
if (windowState() & Qt::WindowMinimized) if (windowState() & Qt::WindowMinimized)
@ -426,7 +426,7 @@ void Widget::confirmExecutableOpen(const QFileInfo file)
if (dangerousExtensions.contains(file.suffix())) if (dangerousExtensions.contains(file.suffix()))
{ {
if(!GUI::askQuestion(tr("Executable file", "popup title"), tr("You have asked qTox to open an executable file. Executable files can potentially damage your computer. Are you sure want to open this file?", "popup text"), false, true)) if (!GUI::askQuestion(tr("Executable file", "popup title"), tr("You have asked qTox to open an executable file. Executable files can potentially damage your computer. Are you sure want to open this file?", "popup text"), false, true))
{ {
return; return;
} }