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()
{
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
{
if(c->scene())
if (c->scene())
c->scene()->removeItem(c);
delete c;
@ -40,15 +40,15 @@ void ChatLine::setRow(int 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);
}
void ChatLine::visibilityChanged(bool visible)
{
if(isVisible != visible)
if (isVisible != visible)
{
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
c->visibilityChanged(visible);
}
@ -62,7 +62,7 @@ int ChatLine::getRow() 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 nullptr;
@ -70,9 +70,9 @@ ChatLineContent *ChatLine::getContent(int col) 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;
}
@ -81,37 +81,37 @@ ChatLineContent *ChatLine::getContent(QPointF scenePos) const
void ChatLine::removeFromScene()
{
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
{
if(c->scene())
if (c->scene())
c->scene()->removeItem(c);
}
}
void ChatLine::addToScene(QGraphicsScene *scene)
{
if(!scene)
if (!scene)
return;
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
scene->addItem(c);
}
void ChatLine::setVisible(bool visible)
{
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
c->setVisible(visible);
}
void ChatLine::selectionCleared()
{
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
c->selectionCleared();
}
void ChatLine::selectionFocusChanged(bool focusIn)
{
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
c->selectionFocusChanged(focusIn);
}
@ -125,7 +125,7 @@ void ChatLine::updateBBox()
bbox.setHeight(0);
bbox.setWidth(width);
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
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)
{
if(!item)
if (!item)
return;
format.push_back(fmt);
@ -145,7 +145,7 @@ void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt)
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();
delete content[col];
@ -153,7 +153,7 @@ void ChatLine::replaceContent(int col, ChatLineContent *lineContent)
content[col] = lineContent;
lineContent->setIndex(row, col);
if(scene)
if (scene)
scene->addItem(content[col]);
layout(width, bbox.topLeft());
@ -170,15 +170,15 @@ void ChatLine::layout(qreal w, QPointF scenePos)
qreal fixedWidth = (content.size()-1) * columnSpacing;
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;
else
varWidth += format[i].size;
}
if(varWidth == 0.0)
if (varWidth == 0.0)
varWidth = 1.0;
qreal leftover = qMax(0.0, width - fixedWidth);
@ -188,11 +188,11 @@ void ChatLine::layout(qreal w, QPointF scenePos)
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
qreal width;
if(format[i].policy == ColumnFormat::FixedSize)
if (format[i].policy == ColumnFormat::FixedSize)
width = format[i].size;
else
width = format[i].size / varWidth * leftover;
@ -222,7 +222,7 @@ void ChatLine::layout(qreal w, QPointF scenePos)
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
// 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)
{
// reposition only
for(ChatLineContent* c : content)
for (ChatLineContent* c : content)
c->moveBy(0, deltaY);
bbox.moveTop(bbox.top() + deltaY);

View File

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

View File

@ -81,7 +81,7 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
setupButtons();
//preview
if(fileInfo.direction == ToxFile::SENDING)
if (fileInfo.direction == ToxFile::SENDING)
{
showPreview(fileInfo.filePath);
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);
number++;
}
while(QFileInfo(filepath).exists());
while (QFileInfo(filepath).exists());
//Do not automatically accept the file-transfer if the path is not writable.
//The user can still accept it manually.
@ -122,11 +122,11 @@ void FileTransferWidget::autoAcceptTransfer(const QString &path)
void FileTransferWidget::acceptTransfer(const QString &filepath)
{
if(filepath.isEmpty())
if (filepath.isEmpty())
return;
//test if writable
if(!Nexus::isFilePathWritable(filepath))
if (!Nexus::isFilePathWritable(filepath))
{
QMessageBox::warning(0,
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)
{
if(c != backgroundColor)
if (c != backgroundColor)
{
backgroundColorAnimation->setStartValue(backgroundColor);
backgroundColorAnimation->setEndValue(c);
@ -157,7 +157,7 @@ void FileTransferWidget::setBackgroundColor(const QColor &c, bool whiteFont)
void FileTransferWidget::setButtonColor(const QColor &c)
{
if(c != buttonColor)
if (c != buttonColor)
{
buttonColorAnimation->setStartValue(buttonColor);
buttonColorAnimation->setEndValue(c);
@ -184,12 +184,12 @@ void FileTransferWidget::paintEvent(QPaintEvent *)
const int lineWidth = 1;
// draw background
if(drawButtonAreaNeeded())
if (drawButtonAreaNeeded())
painter.setClipRect(QRect(0,0,width()-buttonFieldWidth,height()));
painter.setBrush(QBrush(backgroundColor));
painter.drawRoundRect(geometry(), r * ratio, r);
if(drawButtonAreaNeeded())
if (drawButtonAreaNeeded())
{
// draw button background (top)
painter.setBrush(QBrush(buttonColor));
@ -208,12 +208,12 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
QTime now = QTime::currentTime();
qint64 dt = lastTick.msecsTo(now); //ms
if(fileInfo != file || dt < 1000)
if (fileInfo != file || dt < 1000)
return;
fileInfo = file;
if(fileInfo.status == ToxFile::TRANSMITTING)
if (fileInfo.status == ToxFile::TRANSMITTING)
{
// update progress
qreal progress = static_cast<qreal>(file.bytesSent) / static_cast<qreal>(file.filesize);
@ -230,13 +230,13 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
meanData[meanIndex++] = bytesPerSec;
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 /= static_cast<qreal>(TRANSFER_ROLLING_AVG_COUNT);
// update UI
if(meanBytesPerSec > 0)
if (meanBytesPerSec > 0)
{
// ETA
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)
{
if(fileInfo != file)
if (fileInfo != file)
return;
fileInfo = file;
@ -273,7 +273,7 @@ void FileTransferWidget::onFileTransferAccepted(ToxFile file)
void FileTransferWidget::onFileTransferCancelled(ToxFile file)
{
if(fileInfo != file)
if (fileInfo != file)
return;
fileInfo = file;
@ -288,7 +288,7 @@ void FileTransferWidget::onFileTransferCancelled(ToxFile file)
void FileTransferWidget::onFileTransferPaused(ToxFile file)
{
if(fileInfo != file)
if (fileInfo != file)
return;
fileInfo = file;
@ -298,7 +298,7 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
// reset mean
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;
setBackgroundColor(Style::getColor(Style::LightGrey), false);
@ -308,7 +308,7 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
void FileTransferWidget::onFileTransferFinished(ToxFile file)
{
if(fileInfo != file)
if (fileInfo != file)
return;
fileInfo = file;
@ -327,7 +327,7 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file)
ui->bottomButton->show();
// preview
if(fileInfo.direction == ToxFile::RECEIVING)
if (fileInfo.direction == ToxFile::RECEIVING)
showPreview(fileInfo.filePath);
disconnect(Core::getInstance(), 0, this, 0);
@ -382,7 +382,7 @@ void FileTransferWidget::setupButtons()
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/no.svg"));
ui->topButton->setObjectName("cancel");
if(fileInfo.direction == ToxFile::SENDING)
if (fileInfo.direction == ToxFile::SENDING)
{
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/pause.svg"));
ui->bottomButton->setObjectName("pause");
@ -398,31 +398,31 @@ void FileTransferWidget::setupButtons()
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);
else if(btn->objectName() == "pause")
else if (btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "resume")
else if (btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
}
else
{
if(btn->objectName() == "cancel")
if (btn->objectName() == "cancel")
Core::getInstance()->cancelFileRecv(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "pause")
else if (btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
else if(btn->objectName() == "resume")
else if (btn->objectName() == "resume")
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));
acceptTransfer(path);
}
}
if(btn->objectName() == "ok")
if (btn->objectName() == "ok")
{
Widget::confirmExecutableOpen(QFileInfo(fileInfo.filePath));
}
@ -438,7 +438,7 @@ void FileTransferWidget::showPreview(const QString &filename)
{
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());
QPixmap pmap = QPixmap(filename).scaled(QSize(size, size), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);

View File

@ -68,7 +68,7 @@ void NotificationIcon::updateGradient()
{
alpha += 0.01;
if(alpha + dotWidth >= 1.0)
if (alpha + dotWidth >= 1.0)
alpha = 0.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(1, Qt::lightGray);
if(scene() && isVisible())
if (scene() && isVisible())
scene()->invalidate(sceneBoundingRect());
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -225,7 +225,7 @@ void Widget::setTranslation()
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);
if (windowState() & Qt::WindowMinimized)
@ -426,7 +426,7 @@ void Widget::confirmExecutableOpen(const QFileInfo file)
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;
}