From a3b234e6dd598d2d11e757968efd8ede06edfcbf Mon Sep 17 00:00:00 2001 From: sudden6 Date: Thu, 1 Jun 2017 09:50:59 +0200 Subject: [PATCH] chore(formatting): run clang-format --- src/audio/audio.h | 5 ++-- src/audio/backend/openal.cpp | 14 ++++----- src/audio/backend/openal.h | 1 - src/chatlog/chatlog.cpp | 26 ++++++++--------- src/chatlog/content/filetransferwidget.cpp | 34 ++++++++++------------ src/chatlog/content/text.cpp | 5 ++-- src/chatlog/textformatter.cpp | 4 +-- src/ipc.cpp | 5 ++-- src/main.cpp | 6 ++-- src/net/toxuri.cpp | 3 +- src/video/camerasource.cpp | 2 +- src/widget/contentdialog.cpp | 31 +++++++++----------- src/widget/contentdialog.h | 3 +- src/widget/form/chatform.cpp | 3 +- src/widget/form/genericchatform.cpp | 7 ++--- src/widget/form/profileform.cpp | 4 +-- src/widget/friendlistwidget.cpp | 2 +- src/widget/translator.cpp | 3 +- test/chatlog/textformatter_test.cpp | 2 +- updater/update.h | 2 +- 20 files changed, 75 insertions(+), 87 deletions(-) diff --git a/src/audio/audio.h b/src/audio/audio.h index 950bf03b3..bb53bcee0 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -89,13 +89,14 @@ public: virtual void playMono16Sound(const QString& path) = 0; virtual void playAudioBuffer(uint sourceId, const int16_t* data, int samples, unsigned channels, - int sampleRate) = 0; + int sampleRate) = 0; public: // Public default audio settings static constexpr uint32_t AUDIO_SAMPLE_RATE = 48000; static constexpr uint32_t AUDIO_FRAME_DURATION = 20; - static constexpr uint32_t AUDIO_FRAME_SAMPLE_COUNT = AUDIO_FRAME_DURATION * AUDIO_SAMPLE_RATE / 1000; + static constexpr uint32_t AUDIO_FRAME_SAMPLE_COUNT = + AUDIO_FRAME_DURATION * AUDIO_SAMPLE_RATE / 1000; static constexpr uint32_t AUDIO_CHANNELS = 2; signals: diff --git a/src/audio/backend/openal.cpp b/src/audio/backend/openal.cpp index 00dfb3d13..03882b084 100644 --- a/src/audio/backend/openal.cpp +++ b/src/audio/backend/openal.cpp @@ -42,8 +42,8 @@ static const unsigned int BUFFER_COUNT = 16; -OpenAL::OpenAL() : - audioThread{new QThread} +OpenAL::OpenAL() + : audioThread{new QThread} , alInDev{nullptr} , inSubscriptions{0} , alOutDev{nullptr} @@ -364,7 +364,7 @@ void OpenAL::playMono16Sound(const QByteArray& data) } void OpenAL::playAudioBuffer(uint sourceId, const int16_t* data, int samples, unsigned channels, - int sampleRate) + int sampleRate) { assert(channels == 1 || channels == 2); QMutexLocker locker(&audioLock); @@ -463,9 +463,7 @@ void OpenAL::playMono16SoundCleanup() alSourcei(alMainSource, AL_BUFFER, AL_NONE); alDeleteBuffers(1, &alMainBuffer); alMainBuffer = 0; - } - else - { + } else { // the audio didn't finish, try again later playMono16Timer.start(10); } @@ -514,8 +512,8 @@ QStringList OpenAL::outDeviceNames() { QStringList list; const ALchar* pDeviceList = (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE) - ? alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER) - : alcGetString(NULL, ALC_DEVICE_SPECIFIER); + ? alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER) + : alcGetString(NULL, ALC_DEVICE_SPECIFIER); if (pDeviceList) { while (*pDeviceList) { diff --git a/src/audio/backend/openal.h b/src/audio/backend/openal.h index 2d218b09e..d11738ae6 100644 --- a/src/audio/backend/openal.h +++ b/src/audio/backend/openal.h @@ -89,7 +89,6 @@ public: int sampleRate); private: - static void checkAlError() noexcept; static void checkAlcError(ALCdevice* device) noexcept; diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 087beab79..b45112bdb 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -830,21 +830,21 @@ void ChatLog::handleMultiClickEvent() return; switch (clickCount) { - case 3: - QPointF scenePos = mapToScene(lastClickPos); - ChatLineContent* content = getContentFromPos(scenePos); + case 3: + QPointF scenePos = mapToScene(lastClickPos); + ChatLineContent* content = getContentFromPos(scenePos); - if (content) { - content->selectionTripleClick(scenePos); - selClickedCol = content->getColumn(); - selClickedRow = content->getRow(); - selFirstRow = content->getRow(); - selLastRow = content->getRow(); - selectionMode = Precise; + if (content) { + content->selectionTripleClick(scenePos); + selClickedCol = content->getColumn(); + selClickedRow = content->getRow(); + selFirstRow = content->getRow(); + selLastRow = content->getRow(); + selectionMode = Precise; - emit selectionChanged(); - } - break; + emit selectionChanged(); + } + break; } } diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index 26e8c2dce..f522f6fa1 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -99,10 +99,8 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, ToxFile file) &FileTransferWidget::fileTransferRemotePausedUnpaused); connect(Core::getInstance(), &Core::fileTransferBrokenUnbroken, this, &FileTransferWidget::fileTransferBrokenUnbroken); - connect(ui->leftButton, &QPushButton::clicked, this, - &FileTransferWidget::onLeftButtonClicked); - connect(ui->rightButton, &QPushButton::clicked, this, - &FileTransferWidget::onRightButtonClicked); + connect(ui->leftButton, &QPushButton::clicked, this, &FileTransferWidget::onLeftButtonClicked); + connect(ui->rightButton, &QPushButton::clicked, this, &FileTransferWidget::onRightButtonClicked); connect(ui->previewButton, &QPushButton::clicked, this, &FileTransferWidget::onPreviewButtonClicked); @@ -222,32 +220,32 @@ void FileTransferWidget::paintEvent(QPaintEvent*) if (drawButtonAreaNeeded()) { // Draw the button background: QPainterPath buttonBackground; - buttonBackground.addRoundRect(width()-2*buttonFieldWidth-lineWidth*2, 0, buttonFieldWidth, - buttonFieldWidth+lineWidth, 50, 50); - buttonBackground.addRect(width()-2*buttonFieldWidth-lineWidth*2, 0, buttonFieldWidth*2, - buttonFieldWidth/2); - buttonBackground.addRect(width()-1.5*buttonFieldWidth-lineWidth*2, 0, buttonFieldWidth*2, - buttonFieldWidth+1); + buttonBackground.addRoundRect(width() - 2 * buttonFieldWidth - lineWidth * 2, 0, + buttonFieldWidth, buttonFieldWidth + lineWidth, 50, 50); + buttonBackground.addRect(width() - 2 * buttonFieldWidth - lineWidth * 2, 0, + buttonFieldWidth * 2, buttonFieldWidth / 2); + buttonBackground.addRect(width() - 1.5 * buttonFieldWidth - lineWidth * 2, 0, + buttonFieldWidth * 2, buttonFieldWidth + 1); buttonBackground.setFillRule(Qt::WindingFill); painter.setBrush(QBrush(buttonBackgroundColor)); painter.drawPath(buttonBackground); // Draw the left button: QPainterPath leftButton; - leftButton.addRoundRect(QRect(width()-2*buttonFieldWidth-lineWidth, 0, buttonFieldWidth, - buttonFieldWidth), 50, 50); - leftButton.addRect(QRect(width()-2*buttonFieldWidth-lineWidth, 0, buttonFieldWidth/2, - buttonFieldWidth/2)); - leftButton.addRect(QRect(width()-1.5*buttonFieldWidth-lineWidth, 0, buttonFieldWidth/2, - buttonFieldWidth)); + leftButton.addRoundRect(QRect(width() - 2 * buttonFieldWidth - lineWidth, 0, + buttonFieldWidth, buttonFieldWidth), + 50, 50); + leftButton.addRect(QRect(width() - 2 * buttonFieldWidth - lineWidth, 0, + buttonFieldWidth / 2, buttonFieldWidth / 2)); + leftButton.addRect(QRect(width() - 1.5 * buttonFieldWidth - lineWidth, 0, + buttonFieldWidth / 2, buttonFieldWidth)); leftButton.setFillRule(Qt::WindingFill); painter.setBrush(QBrush(buttonColor)); painter.drawPath(leftButton); // Draw the right button: painter.setBrush(QBrush(buttonColor)); - painter.setClipRect(QRect(width()-buttonFieldWidth, 0, buttonFieldWidth, - buttonFieldWidth)); + painter.setClipRect(QRect(width() - buttonFieldWidth, 0, buttonFieldWidth, buttonFieldWidth)); painter.drawRoundRect(geometry(), r * ratio, r); } } diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index 1dd1b1189..560086f0d 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -366,9 +366,8 @@ QString Text::extractSanitizedText(int from, int to) const QTextBlock end = doc->findBlock(to); for (QTextBlock block = begin; block != end.next() && block.isValid(); block = block.next()) { 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()) { QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat(); diff --git a/src/chatlog/textformatter.cpp b/src/chatlog/textformatter.cpp index 0b5e2fcee..e0cbcf721 100644 --- a/src/chatlog/textformatter.cpp +++ b/src/chatlog/textformatter.cpp @@ -174,7 +174,7 @@ static void processUrl(QString& str, std::function func) */ void TextFormatter::applyHtmlFontStyling(bool showFormattingSymbols) { - processUrl(message, [] (QString& str) { + processUrl(message, [](QString& str) { for (char c : MARKDOWN_SYMBOLS) { QString charCode = QString::number(static_cast(c)); str.replace(c, HTML_CHARACTER_CODE.arg(charCode)); @@ -217,7 +217,7 @@ void TextFormatter::applyHtmlFontStyling(bool showFormattingSymbols) */ void TextFormatter::wrapUrl() { - processUrl(message, [] (QString& str) { + processUrl(message, [](QString& str) { return htmlPatterns[TextStyle::HREF].arg(str.startsWith("www") ? "http://" : "", str); }); } diff --git a/src/ipc.cpp b/src/ipc.cpp index 4fa913fb8..253ecb893 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -21,9 +21,9 @@ #include #include #include +#include #include #include -#include /** * @var time_t IPC::lastEvent @@ -216,8 +216,7 @@ IPC::IPCEvent* IPC::fetchEvent() memset(evt, 0, sizeof(IPCEvent)); if (evt->posted && !evt->processed && evt->sender != getpid() - && (evt->dest == profileId - || (evt->dest == 0 && isCurrentOwner()))) + && (evt->dest == profileId || (evt->dest == 0 && isCurrentOwner()))) return evt; } diff --git a/src/main.cpp b/src/main.cpp index 67549bfd9..874d65215 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,9 +38,9 @@ #include #include +#include #include #include -#include #if defined(Q_OS_OSX) #include "platform/install_osx.h" @@ -168,8 +168,8 @@ int main(int argc, char* argv[]) uint32_t profileId = Settings::getInstance().getCurrentProfileId(); IPC ipc(profileId); - QObject::connect(&Settings::getInstance(), &Settings::currentProfileIdChanged, - &ipc, &IPC::setProfileId); + QObject::connect(&Settings::getInstance(), &Settings::currentProfileIdChanged, &ipc, + &IPC::setProfileId); if (sodium_init() < 0) // For the auto-updater { diff --git a/src/net/toxuri.cpp b/src/net/toxuri.cpp index 4a51d75d9..22537af69 100644 --- a/src/net/toxuri.cpp +++ b/src/net/toxuri.cpp @@ -91,7 +91,8 @@ bool handleToxURI(const QString& toxURI) return false; } - const QString defaultMessage = QObject::tr("%1 here! Tox me maybe?", + const QString defaultMessage = + QObject::tr("%1 here! Tox me maybe?", "Default message in Tox URI friend requests. Write something appropriate!"); const QString username = Nexus::getCore()->getUsername(); ToxURIDialog* dialog = new ToxURIDialog(nullptr, toxaddr, defaultMessage.arg(username)); diff --git a/src/video/camerasource.cpp b/src/video/camerasource.cpp index f0860894f..8eec818ce 100644 --- a/src/video/camerasource.cpp +++ b/src/video/camerasource.cpp @@ -93,7 +93,7 @@ CameraSource::CameraSource() : deviceName{"none"} , device{nullptr} , mode(VideoMode()) -// clang-format off + // clang-format off , cctx{nullptr} #if LIBAVCODEC_VERSION_INT < 3747941 , cctxOrig{nullptr} diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index c500208ef..19592f978 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -69,11 +69,8 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent) friendLayout->setMargin(0); friendLayout->setSpacing(0); - layouts = { - friendLayout->getLayoutOnline(), - groupLayout.getLayout(), - friendLayout->getLayoutOffline() - }; + layouts = {friendLayout->getLayoutOnline(), groupLayout.getLayout(), + friendLayout->getLayoutOffline()}; if (s.getGroupchatPosition()) { layouts.swap(0, 1); @@ -141,8 +138,9 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent) Translator::registerHandler(std::bind(&ContentDialog::retranslateUi, this), this); } -void ContentDialog::removeCurrent(QHash& infos) { - for (auto it = infos.begin(); it != infos.end(); ) { +void ContentDialog::removeCurrent(QHash& infos) +{ + for (auto it = infos.begin(); it != infos.end();) { if (std::get<0>(*it) == this) { it = infos.erase(it); } else { @@ -354,9 +352,9 @@ void ContentDialog::cycleContacts(bool forward, bool inverse) bool isCurOffline = currentLayout == friendLayout->getLayoutOffline(); bool isCurOnline = currentLayout == friendLayout->getLayoutOnline(); bool isCurGroup = currentLayout == groupLayout.getLayout(); - bool nextIsEmpty = (isCurOnline && offlineEmpty && (groupsEmpty || groupsOnTop)) || - (isCurGroup && offlineEmpty && (onlineEmpty || !groupsOnTop)) || - isCurOffline; + bool nextIsEmpty = (isCurOnline && offlineEmpty && (groupsEmpty || groupsOnTop)) + || (isCurGroup && offlineEmpty && (onlineEmpty || !groupsOnTop)) + || isCurOffline; if (nextIsEmpty) { forward = !forward; @@ -509,12 +507,10 @@ void ContentDialog::updateTitleAndStatusIcon() Status currentStatus = activeChatroomWidget->getFriend()->getStatus(); - QMap icons { - {Status::Online, QIcon(":/img/status/dot_online.svg")}, - {Status::Away, QIcon(":/img/status/dot_away.svg")}, - {Status::Busy, QIcon(":/img/status/dot_busy.svg")}, - {Status::Offline, QIcon(":/img/status/dot_offline.svg")} - }; + QMap icons{{Status::Online, QIcon(":/img/status/dot_online.svg")}, + {Status::Away, QIcon(":/img/status/dot_away.svg")}, + {Status::Busy, QIcon(":/img/status/dot_busy.svg")}, + {Status::Offline, QIcon(":/img/status/dot_offline.svg")}}; setWindowIcon(icons[currentStatus]); } @@ -821,8 +817,7 @@ bool ContentDialog::hasWidget(int id, GenericChatroomWidget* chatroomWidget, return false; } - return std::get<0>(*iter) == this && - std::get<1>(*iter) == chatroomWidget; + return std::get<0>(*iter) == this && std::get<1>(*iter) == chatroomWidget; } /** diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 8f6c216ad..9f0a0d53e 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -112,8 +112,7 @@ private: QLayout* nextLayout(QLayout* layout, bool forward) const; int getCurrentLayout(QLayout*& layout); - bool hasWidget(int id, GenericChatroomWidget* chatroomWidget, - const QHash& list); + bool hasWidget(int id, GenericChatroomWidget* chatroomWidget, const QHash& list); void removeCurrent(QHash& infos); static bool existsWidget(int id, const QHash& list); static void focusDialog(int id, const QHash& list); diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 34c9f27cb..bb4bf5856 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -610,7 +610,8 @@ void ChatForm::dropEvent(QDropEvent* ev) QFile file(info.absoluteFilePath()); QString urlString = url.toString(); - if (url.isValid() && !url.isLocalFile() && urlString.length() < static_cast(tox_max_message_length())) { + if (url.isValid() && !url.isLocalFile() + && urlString.length() < static_cast(tox_max_message_length())) { SendMessageStr(urlString); continue; } diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 286ad3eed..b4163008e 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -55,7 +55,7 @@ * (excluded) */ -#define SET_STYLESHEET(x) (x)->setStyleSheet(Style::getStylesheet(":/ui/"#x"/"#x".css")) +#define SET_STYLESHEET(x) (x)->setStyleSheet(Style::getStylesheet(":/ui/" #x "/" #x ".css")) static const QSize AVATAR_SIZE{40, 40}; static const QSize CALL_BUTTONS_SIZE{50, 40}; @@ -380,7 +380,7 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos) * @param messageAuthor Author of the sent message * @return True if it's needed to hide name, false otherwise */ -bool GenericChatForm::needsToHideName(const ToxPk &messageAuthor) const +bool GenericChatForm::needsToHideName(const ToxPk& messageAuthor) const { qint64 messagesTimeDiff = prevMsgDateTime.secsTo(QDateTime::currentDateTime()); return messageAuthor == previousId && messagesTimeDiff < chatWidget->repNameAfter; @@ -451,8 +451,7 @@ void GenericChatForm::addMessage(const ToxPk& author, const QString& message, co /** * @brief Inserts int ChatLog message that you have sent */ -void GenericChatForm::addSelfMessage(const QString& message, const QDateTime& datetime, - bool isAction) +void GenericChatForm::addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction) { createSelfMessage(message, datetime, isAction, true); } diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 693014489..65b52aa21 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -56,8 +56,8 @@ ProfileForm::ProfileForm(QWidget* parent) bodyUI->setupUi(this); core = Core::getInstance(); - bodyUI->userNameLabel->setToolTip(tr("Tox user names cannot exceed %1 characters.") - .arg(tox_max_name_length())); + bodyUI->userNameLabel->setToolTip( + tr("Tox user names cannot exceed %1 characters.").arg(tox_max_name_length())); bodyUI->userName->setMaxLength(tox_max_name_length()); // tox diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index 0a84e214c..00ee7adf8 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -209,7 +209,7 @@ void FriendListWidget::setMode(Mode mode) { Time::Month4Ago, ql.monthName(today.addMonths(-4).month()) }, { Time::Month5Ago, ql.monthName(today.addMonths(-5).month()) }, }; - // clang-format on +// clang-format on #undef COMMENT activityLayout = new QVBoxLayout(); diff --git a/src/widget/translator.cpp b/src/widget/translator.cpp index 7a63ca58c..2091df15d 100644 --- a/src/widget/translator.cpp +++ b/src/widget/translator.cpp @@ -44,8 +44,7 @@ void Translator::translate(const QString& localeName) // Load translations QCoreApplication::removeTranslator(translator); - QString locale = localeName.isEmpty() ? QLocale::system().name().section('_', 0, 0) - : localeName; + QString locale = localeName.isEmpty() ? QLocale::system().name().section('_', 0, 0) : localeName; if (locale != "en") { if (translator->load(locale, ":translations/")) { diff --git a/test/chatlog/textformatter_test.cpp b/test/chatlog/textformatter_test.cpp index 8fcb5a8b3..b98cdfd35 100644 --- a/test/chatlog/textformatter_test.cpp +++ b/test/chatlog/textformatter_test.cpp @@ -75,7 +75,7 @@ static const StringToString multilineCode{ {QStringLiteral("```int main()\n{\n return 0;\n}```"), QStringLiteral("int main()\n{\n return 0;\n}")}}; -static const StringToString urlCases { +static const StringToString urlCases{ {QStringLiteral("https://github.com/qTox/qTox/issues/4233"), QStringLiteral("" "https://github.com/qTox/qTox/issues/4233")}, diff --git a/updater/update.h b/updater/update.h index 24b41c204..321edf13b 100644 --- a/updater/update.h +++ b/updater/update.h @@ -32,7 +32,7 @@ struct UpdateFileMeta unsigned char sig[crypto_sign_BYTES]; ///< Signature of the file (ed25519) QString id; ///< Unique id of the file QString installpath; ///< Local path including the file name. May be relative to qtox-updater or - ///absolute + /// absolute uint64_t size; ///< Size in bytes of the file bool operator==(const UpdateFileMeta& other)