Normalize line endings in already existing files
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "DebugCount.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
UniqueAccess<QMap<QString, int64_t>> DebugCount::counts_;
|
||||
|
||||
} // namespace chatterino
|
||||
#include "DebugCount.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
UniqueAccess<QMap<QString, int64_t>> DebugCount::counts_;
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+67
-67
@@ -1,67 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/UniqueAccess.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <typeinfo>
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class DebugCount
|
||||
{
|
||||
public:
|
||||
static void increase(const QString &name)
|
||||
{
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end())
|
||||
{
|
||||
counts->insert(name, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
reinterpret_cast<int64_t &>(it.value())++;
|
||||
}
|
||||
}
|
||||
|
||||
static void decrease(const QString &name)
|
||||
{
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end())
|
||||
{
|
||||
counts->insert(name, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
reinterpret_cast<int64_t &>(it.value())--;
|
||||
}
|
||||
}
|
||||
|
||||
static QString getDebugText()
|
||||
{
|
||||
auto counts = counts_.access();
|
||||
|
||||
QString text;
|
||||
for (auto it = counts->begin(); it != counts->end(); it++)
|
||||
{
|
||||
text += it.key() + ": " + QString::number(it.value()) + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
QString toString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
private:
|
||||
static UniqueAccess<QMap<QString, int64_t>> counts_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <common/UniqueAccess.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <typeinfo>
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class DebugCount
|
||||
{
|
||||
public:
|
||||
static void increase(const QString &name)
|
||||
{
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end())
|
||||
{
|
||||
counts->insert(name, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
reinterpret_cast<int64_t &>(it.value())++;
|
||||
}
|
||||
}
|
||||
|
||||
static void decrease(const QString &name)
|
||||
{
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end())
|
||||
{
|
||||
counts->insert(name, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
reinterpret_cast<int64_t &>(it.value())--;
|
||||
}
|
||||
}
|
||||
|
||||
static QString getDebugText()
|
||||
{
|
||||
auto counts = counts_.access();
|
||||
|
||||
QString text;
|
||||
for (auto it = counts->begin(); it != counts->end(); it++)
|
||||
{
|
||||
text += it.key() + ": " + QString::number(it.value()) + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
QString toString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
private:
|
||||
static UniqueAccess<QMap<QString, int64_t>> counts_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+53
-53
@@ -1,53 +1,53 @@
|
||||
#include "FormatTime.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
void appendDuration(int count, QChar &&order, QString &outString)
|
||||
{
|
||||
outString.append(QString::number(count));
|
||||
outString.append(order);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
QString formatTime(int totalSeconds)
|
||||
{
|
||||
QString res;
|
||||
|
||||
int seconds = totalSeconds % 60;
|
||||
int timeoutMinutes = totalSeconds / 60;
|
||||
int minutes = timeoutMinutes % 60;
|
||||
int timeoutHours = timeoutMinutes / 60;
|
||||
int hours = timeoutHours % 24;
|
||||
int days = timeoutHours / 24;
|
||||
if (days > 0)
|
||||
{
|
||||
appendDuration(days, 'd', res);
|
||||
}
|
||||
if (hours > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(hours, 'h', res);
|
||||
}
|
||||
if (minutes > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(minutes, 'm', res);
|
||||
}
|
||||
if (seconds > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(seconds, 's', res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "FormatTime.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
void appendDuration(int count, QChar &&order, QString &outString)
|
||||
{
|
||||
outString.append(QString::number(count));
|
||||
outString.append(order);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
QString formatTime(int totalSeconds)
|
||||
{
|
||||
QString res;
|
||||
|
||||
int seconds = totalSeconds % 60;
|
||||
int timeoutMinutes = totalSeconds / 60;
|
||||
int minutes = timeoutMinutes % 60;
|
||||
int timeoutHours = timeoutMinutes / 60;
|
||||
int hours = timeoutHours % 24;
|
||||
int days = timeoutHours / 24;
|
||||
if (days > 0)
|
||||
{
|
||||
appendDuration(days, 'd', res);
|
||||
}
|
||||
if (hours > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(hours, 'h', res);
|
||||
}
|
||||
if (minutes > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(minutes, 'm', res);
|
||||
}
|
||||
if (seconds > 0)
|
||||
{
|
||||
if (!res.isEmpty())
|
||||
{
|
||||
res.append(" ");
|
||||
}
|
||||
appendDuration(seconds, 's', res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// format: 1h 23m 42s
|
||||
QString formatTime(int totalSeconds);
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// format: 1h 23m 42s
|
||||
QString formatTime(int totalSeconds);
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
#include "IncognitoBrowser.hpp"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
|
||||
#include "debug/Log.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
#ifdef Q_OS_WIN
|
||||
QString injectPrivateSwitch(QString command)
|
||||
{
|
||||
// list of command line switches to turn on private browsing in browsers
|
||||
static auto switches = std::vector<std::pair<QString, QString>>{
|
||||
{"firefox", "-private-window"}, {"chrome", "-incognito"},
|
||||
{"vivaldi", "-incognito"}, {"opera", "-newprivatetab"},
|
||||
{"opera\\\\launcher", "--private"}, {"iexplore", "-private"},
|
||||
};
|
||||
|
||||
// transform into regex and replacement string
|
||||
std::vector<std::pair<QRegularExpression, QString>> replacers;
|
||||
for (const auto &switch_ : switches)
|
||||
{
|
||||
replacers.emplace_back(
|
||||
QRegularExpression("(" + switch_.first + "\\.exe\"?).*",
|
||||
QRegularExpression::CaseInsensitiveOption),
|
||||
"\\1 " + switch_.second);
|
||||
}
|
||||
|
||||
// try to find matching regex and apply it
|
||||
for (const auto &replacement : replacers)
|
||||
{
|
||||
if (replacement.first.match(command).hasMatch())
|
||||
{
|
||||
command.replace(replacement.first, replacement.second);
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
// couldn't match any browser -> unknown browser
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString getCommand(const QString &link)
|
||||
{
|
||||
// get default browser prog id
|
||||
auto browserId = QSettings("HKEY_CURRENT_"
|
||||
"USER\\Software\\Microsoft\\Windows\\Shell\\"
|
||||
"Associations\\UrlAssociatio"
|
||||
"ns\\http\\UserChoice",
|
||||
QSettings::NativeFormat)
|
||||
.value("Progid")
|
||||
.toString();
|
||||
|
||||
// get default browser start command
|
||||
auto command = QSettings("HKEY_CLASSES_ROOT\\" + browserId +
|
||||
"\\shell\\open\\command",
|
||||
QSettings::NativeFormat)
|
||||
.value("Default")
|
||||
.toString();
|
||||
if (command.isNull())
|
||||
return QString();
|
||||
|
||||
log(command);
|
||||
|
||||
// inject switch to enable private browsing
|
||||
command = injectPrivateSwitch(command);
|
||||
if (command.isNull())
|
||||
return QString();
|
||||
|
||||
// link
|
||||
command += " " + link;
|
||||
|
||||
return command;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
bool supportsIncognitoLinks()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return !getCommand("").isNull();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void openLinkIncognito(const QString &link)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
auto command = getCommand(link);
|
||||
|
||||
QProcess::startDetached(command);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "IncognitoBrowser.hpp"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
|
||||
#include "debug/Log.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
#ifdef Q_OS_WIN
|
||||
QString injectPrivateSwitch(QString command)
|
||||
{
|
||||
// list of command line switches to turn on private browsing in browsers
|
||||
static auto switches = std::vector<std::pair<QString, QString>>{
|
||||
{"firefox", "-private-window"}, {"chrome", "-incognito"},
|
||||
{"vivaldi", "-incognito"}, {"opera", "-newprivatetab"},
|
||||
{"opera\\\\launcher", "--private"}, {"iexplore", "-private"},
|
||||
};
|
||||
|
||||
// transform into regex and replacement string
|
||||
std::vector<std::pair<QRegularExpression, QString>> replacers;
|
||||
for (const auto &switch_ : switches)
|
||||
{
|
||||
replacers.emplace_back(
|
||||
QRegularExpression("(" + switch_.first + "\\.exe\"?).*",
|
||||
QRegularExpression::CaseInsensitiveOption),
|
||||
"\\1 " + switch_.second);
|
||||
}
|
||||
|
||||
// try to find matching regex and apply it
|
||||
for (const auto &replacement : replacers)
|
||||
{
|
||||
if (replacement.first.match(command).hasMatch())
|
||||
{
|
||||
command.replace(replacement.first, replacement.second);
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
// couldn't match any browser -> unknown browser
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString getCommand(const QString &link)
|
||||
{
|
||||
// get default browser prog id
|
||||
auto browserId = QSettings("HKEY_CURRENT_"
|
||||
"USER\\Software\\Microsoft\\Windows\\Shell\\"
|
||||
"Associations\\UrlAssociatio"
|
||||
"ns\\http\\UserChoice",
|
||||
QSettings::NativeFormat)
|
||||
.value("Progid")
|
||||
.toString();
|
||||
|
||||
// get default browser start command
|
||||
auto command = QSettings("HKEY_CLASSES_ROOT\\" + browserId +
|
||||
"\\shell\\open\\command",
|
||||
QSettings::NativeFormat)
|
||||
.value("Default")
|
||||
.toString();
|
||||
if (command.isNull())
|
||||
return QString();
|
||||
|
||||
log(command);
|
||||
|
||||
// inject switch to enable private browsing
|
||||
command = injectPrivateSwitch(command);
|
||||
if (command.isNull())
|
||||
return QString();
|
||||
|
||||
// link
|
||||
command += " " + link;
|
||||
|
||||
return command;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
bool supportsIncognitoLinks()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return !getCommand("").isNull();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void openLinkIncognito(const QString &link)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
auto command = getCommand(link);
|
||||
|
||||
QProcess::startDetached(command);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
bool supportsIncognitoLinks();
|
||||
void openLinkIncognito(const QString &link);
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
bool supportsIncognitoLinks();
|
||||
void openLinkIncognito(const QString &link);
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
#include "InitUpdateButton.hpp"
|
||||
|
||||
#include "widgets/dialogs/UpdateDialog.hpp"
|
||||
#include "widgets/helper/Button.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void initUpdateButton(Button &button,
|
||||
pajlada::Signals::SignalHolder &signalHolder)
|
||||
{
|
||||
button.hide();
|
||||
|
||||
// show update prompt when clicking the button
|
||||
QObject::connect(&button, &Button::leftClicked, [&button] {
|
||||
auto dialog = new UpdateDialog();
|
||||
dialog->setActionOnFocusLoss(BaseWindow::Delete);
|
||||
dialog->move(button.mapToGlobal(
|
||||
QPoint(int(-100 * button.scale()), button.height())));
|
||||
dialog->show();
|
||||
dialog->raise();
|
||||
|
||||
dialog->buttonClicked.connect([&button](auto buttonType) {
|
||||
switch (buttonType)
|
||||
{
|
||||
case UpdateDialog::Dismiss:
|
||||
{
|
||||
button.hide();
|
||||
}
|
||||
break;
|
||||
case UpdateDialog::Install:
|
||||
{
|
||||
Updates::getInstance().installUpdates();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// handle.reset(dialog);
|
||||
// dialog->closing.connect([&handle] { handle.release(); });
|
||||
});
|
||||
|
||||
// update image when state changes
|
||||
auto updateChange = [&button](auto) {
|
||||
button.setVisible(Updates::getInstance().shouldShowUpdateButton());
|
||||
|
||||
auto imageUrl = Updates::getInstance().isError()
|
||||
? ":/buttons/updateError.png"
|
||||
: ":/buttons/update.png";
|
||||
button.setPixmap(QPixmap(imageUrl));
|
||||
};
|
||||
|
||||
updateChange(Updates::getInstance().getStatus());
|
||||
|
||||
signalHolder.managedConnect(
|
||||
Updates::getInstance().statusUpdated,
|
||||
[updateChange](auto status) { updateChange(status); });
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "InitUpdateButton.hpp"
|
||||
|
||||
#include "widgets/dialogs/UpdateDialog.hpp"
|
||||
#include "widgets/helper/Button.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void initUpdateButton(Button &button,
|
||||
pajlada::Signals::SignalHolder &signalHolder)
|
||||
{
|
||||
button.hide();
|
||||
|
||||
// show update prompt when clicking the button
|
||||
QObject::connect(&button, &Button::leftClicked, [&button] {
|
||||
auto dialog = new UpdateDialog();
|
||||
dialog->setActionOnFocusLoss(BaseWindow::Delete);
|
||||
dialog->move(button.mapToGlobal(
|
||||
QPoint(int(-100 * button.scale()), button.height())));
|
||||
dialog->show();
|
||||
dialog->raise();
|
||||
|
||||
dialog->buttonClicked.connect([&button](auto buttonType) {
|
||||
switch (buttonType)
|
||||
{
|
||||
case UpdateDialog::Dismiss:
|
||||
{
|
||||
button.hide();
|
||||
}
|
||||
break;
|
||||
case UpdateDialog::Install:
|
||||
{
|
||||
Updates::getInstance().installUpdates();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// handle.reset(dialog);
|
||||
// dialog->closing.connect([&handle] { handle.release(); });
|
||||
});
|
||||
|
||||
// update image when state changes
|
||||
auto updateChange = [&button](auto) {
|
||||
button.setVisible(Updates::getInstance().shouldShowUpdateButton());
|
||||
|
||||
auto imageUrl = Updates::getInstance().isError()
|
||||
? ":/buttons/updateError.png"
|
||||
: ":/buttons/update.png";
|
||||
button.setPixmap(QPixmap(imageUrl));
|
||||
};
|
||||
|
||||
updateChange(Updates::getInstance().getStatus());
|
||||
|
||||
signalHolder.managedConnect(
|
||||
Updates::getInstance().statusUpdated,
|
||||
[updateChange](auto status) { updateChange(status); });
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace pajlada {
|
||||
namespace Signals {
|
||||
class SignalHolder;
|
||||
}
|
||||
} // namespace pajlada
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Button;
|
||||
class UpdateDialog;
|
||||
|
||||
void initUpdateButton(Button &button,
|
||||
pajlada::Signals::SignalHolder &signalHolder);
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace pajlada {
|
||||
namespace Signals {
|
||||
class SignalHolder;
|
||||
}
|
||||
} // namespace pajlada
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Button;
|
||||
class UpdateDialog;
|
||||
|
||||
void initUpdateButton(Button &button,
|
||||
pajlada::Signals::SignalHolder &signalHolder);
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+13
-13
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
bool isBigEndian()
|
||||
{
|
||||
int test = 1;
|
||||
char *p = reinterpret_cast<char *>(&test);
|
||||
|
||||
return p[0] == 0;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
bool isBigEndian()
|
||||
{
|
||||
int test = 1;
|
||||
char *p = reinterpret_cast<char *>(&test);
|
||||
|
||||
return p[0] == 0;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+172
-172
@@ -1,172 +1,172 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollArea>
|
||||
#include <QTabWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <class T>
|
||||
class LayoutCreator
|
||||
{
|
||||
public:
|
||||
LayoutCreator(T *_item)
|
||||
: item_(_item)
|
||||
{
|
||||
}
|
||||
|
||||
T *operator->()
|
||||
{
|
||||
return this->item_;
|
||||
}
|
||||
|
||||
T &operator*()
|
||||
{
|
||||
return *this->item_;
|
||||
}
|
||||
|
||||
T *getElement()
|
||||
{
|
||||
return this->item_;
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
LayoutCreator<T2> append(T2 *_item)
|
||||
{
|
||||
this->addItem(this->getOrCreateLayout(), _item);
|
||||
|
||||
return LayoutCreator<T2>(_item);
|
||||
}
|
||||
|
||||
template <typename T2, typename... Args>
|
||||
LayoutCreator<T2> emplace(Args &&... args)
|
||||
{
|
||||
T2 *t = new T2(std::forward<Args>(args)...);
|
||||
|
||||
this->addItem(this->getOrCreateLayout(), t);
|
||||
|
||||
return LayoutCreator<T2>(t);
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QScrollArea, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<QWidget> emplaceScrollAreaWidget()
|
||||
{
|
||||
QWidget *widget = new QWidget;
|
||||
this->item_->setWidget(widget);
|
||||
return LayoutCreator<QWidget>(widget);
|
||||
}
|
||||
|
||||
template <typename T2, typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QWidget, Q>::value,
|
||||
int>::type = 0,
|
||||
typename std::enable_if<std::is_base_of<QLayout, T2>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T2> setLayoutType()
|
||||
{
|
||||
T2 *layout = new T2;
|
||||
|
||||
this->item_->setLayout(layout);
|
||||
|
||||
return LayoutCreator<T2>(layout);
|
||||
}
|
||||
|
||||
LayoutCreator<T> assign(T **ptr)
|
||||
{
|
||||
*ptr = this->item_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QLayout, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T> withoutMargin()
|
||||
{
|
||||
this->item_->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
LayoutCreator<T> withoutSpacing()
|
||||
{
|
||||
this->item_->setSpacing(0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QWidget, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T> hidden()
|
||||
{
|
||||
this->item_->setVisible(false);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Q = T, typename T2,
|
||||
typename std::enable_if<std::is_same<QTabWidget, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T2> appendTab(T2 *item, const QString &title)
|
||||
{
|
||||
static_assert(std::is_base_of<QLayout, T2>::value,
|
||||
"needs to be QLayout");
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(item);
|
||||
|
||||
this->item_->addTab(widget, title);
|
||||
|
||||
return LayoutCreator<T2>(item);
|
||||
}
|
||||
|
||||
private:
|
||||
T *item_;
|
||||
|
||||
template <typename T2,
|
||||
typename std::enable_if<std::is_base_of<QWidget, T2>::value,
|
||||
int>::type = 0>
|
||||
void addItem(QLayout *layout, T2 *item)
|
||||
{
|
||||
layout->addWidget(item);
|
||||
}
|
||||
|
||||
template <typename T2,
|
||||
typename std::enable_if<std::is_base_of<QLayout, T2>::value,
|
||||
int>::type = 0>
|
||||
void addItem(QLayout *layout, T2 *item)
|
||||
{
|
||||
QWidget *widget = new QWidget();
|
||||
widget->setLayout(item);
|
||||
layout->addWidget(widget);
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QLayout, Q>::value,
|
||||
int>::type = 0>
|
||||
QLayout *getOrCreateLayout()
|
||||
{
|
||||
return this->item_;
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QWidget, Q>::value,
|
||||
int>::type = 0>
|
||||
QLayout *getOrCreateLayout()
|
||||
{
|
||||
if (!this->item_->layout())
|
||||
{
|
||||
this->item_->setLayout(new QHBoxLayout());
|
||||
}
|
||||
|
||||
return this->item_->layout();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollArea>
|
||||
#include <QTabWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <class T>
|
||||
class LayoutCreator
|
||||
{
|
||||
public:
|
||||
LayoutCreator(T *_item)
|
||||
: item_(_item)
|
||||
{
|
||||
}
|
||||
|
||||
T *operator->()
|
||||
{
|
||||
return this->item_;
|
||||
}
|
||||
|
||||
T &operator*()
|
||||
{
|
||||
return *this->item_;
|
||||
}
|
||||
|
||||
T *getElement()
|
||||
{
|
||||
return this->item_;
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
LayoutCreator<T2> append(T2 *_item)
|
||||
{
|
||||
this->addItem(this->getOrCreateLayout(), _item);
|
||||
|
||||
return LayoutCreator<T2>(_item);
|
||||
}
|
||||
|
||||
template <typename T2, typename... Args>
|
||||
LayoutCreator<T2> emplace(Args &&... args)
|
||||
{
|
||||
T2 *t = new T2(std::forward<Args>(args)...);
|
||||
|
||||
this->addItem(this->getOrCreateLayout(), t);
|
||||
|
||||
return LayoutCreator<T2>(t);
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QScrollArea, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<QWidget> emplaceScrollAreaWidget()
|
||||
{
|
||||
QWidget *widget = new QWidget;
|
||||
this->item_->setWidget(widget);
|
||||
return LayoutCreator<QWidget>(widget);
|
||||
}
|
||||
|
||||
template <typename T2, typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QWidget, Q>::value,
|
||||
int>::type = 0,
|
||||
typename std::enable_if<std::is_base_of<QLayout, T2>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T2> setLayoutType()
|
||||
{
|
||||
T2 *layout = new T2;
|
||||
|
||||
this->item_->setLayout(layout);
|
||||
|
||||
return LayoutCreator<T2>(layout);
|
||||
}
|
||||
|
||||
LayoutCreator<T> assign(T **ptr)
|
||||
{
|
||||
*ptr = this->item_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QLayout, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T> withoutMargin()
|
||||
{
|
||||
this->item_->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
LayoutCreator<T> withoutSpacing()
|
||||
{
|
||||
this->item_->setSpacing(0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QWidget, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T> hidden()
|
||||
{
|
||||
this->item_->setVisible(false);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Q = T, typename T2,
|
||||
typename std::enable_if<std::is_same<QTabWidget, Q>::value,
|
||||
int>::type = 0>
|
||||
LayoutCreator<T2> appendTab(T2 *item, const QString &title)
|
||||
{
|
||||
static_assert(std::is_base_of<QLayout, T2>::value,
|
||||
"needs to be QLayout");
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(item);
|
||||
|
||||
this->item_->addTab(widget, title);
|
||||
|
||||
return LayoutCreator<T2>(item);
|
||||
}
|
||||
|
||||
private:
|
||||
T *item_;
|
||||
|
||||
template <typename T2,
|
||||
typename std::enable_if<std::is_base_of<QWidget, T2>::value,
|
||||
int>::type = 0>
|
||||
void addItem(QLayout *layout, T2 *item)
|
||||
{
|
||||
layout->addWidget(item);
|
||||
}
|
||||
|
||||
template <typename T2,
|
||||
typename std::enable_if<std::is_base_of<QLayout, T2>::value,
|
||||
int>::type = 0>
|
||||
void addItem(QLayout *layout, T2 *item)
|
||||
{
|
||||
QWidget *widget = new QWidget();
|
||||
widget->setLayout(item);
|
||||
layout->addWidget(widget);
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QLayout, Q>::value,
|
||||
int>::type = 0>
|
||||
QLayout *getOrCreateLayout()
|
||||
{
|
||||
return this->item_;
|
||||
}
|
||||
|
||||
template <typename Q = T,
|
||||
typename std::enable_if<std::is_base_of<QWidget, Q>::value,
|
||||
int>::type = 0>
|
||||
QLayout *getOrCreateLayout()
|
||||
{
|
||||
if (!this->item_->layout())
|
||||
{
|
||||
this->item_->setLayout(new QHBoxLayout());
|
||||
}
|
||||
|
||||
return this->item_->layout();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+16
-16
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<QString> {
|
||||
std::size_t operator()(const QString &s) const
|
||||
{
|
||||
return qHash(s);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<QString> {
|
||||
std::size_t operator()(const QString &s) const
|
||||
{
|
||||
return qHash(s);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <QScrollArea>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static void removeScrollAreaBackground(QScrollArea *scrollArea,
|
||||
QWidget *childWidget)
|
||||
{
|
||||
scrollArea->setWidgetResizable(true);
|
||||
scrollArea->setFrameStyle(0);
|
||||
|
||||
QPalette p;
|
||||
p.setColor(QPalette::Background, QColor(0, 0, 0, 0));
|
||||
scrollArea->setPalette(p);
|
||||
childWidget->setPalette(p);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <QScrollArea>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static void removeScrollAreaBackground(QScrollArea *scrollArea,
|
||||
QWidget *childWidget)
|
||||
{
|
||||
scrollArea->setWidgetResizable(true);
|
||||
scrollArea->setFrameStyle(0);
|
||||
|
||||
QPalette p;
|
||||
p.setColor(QPalette::Background, QColor(0, 0, 0, 0));
|
||||
scrollArea->setPalette(p);
|
||||
childWidget->setPalette(p);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename T>
|
||||
struct SharedPtrElementLess {
|
||||
bool operator()(const std::shared_ptr<T> &a,
|
||||
const std::shared_ptr<T> &b) const
|
||||
{
|
||||
return a->operator<(*b);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename T>
|
||||
struct SharedPtrElementLess {
|
||||
bool operator()(const std::shared_ptr<T> &a,
|
||||
const std::shared_ptr<T> &b) const
|
||||
{
|
||||
return a->operator<(*b);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QStandardItem>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static void setBoolItem(QStandardItem *item, bool value,
|
||||
bool userCheckable = true, bool selectable = true)
|
||||
{
|
||||
item->setFlags((Qt::ItemFlags)(
|
||||
Qt::ItemIsEnabled | (selectable ? Qt::ItemIsSelectable : 0) |
|
||||
(userCheckable ? Qt::ItemIsUserCheckable : 0)));
|
||||
item->setCheckState(value ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
|
||||
static void setStringItem(QStandardItem *item, const QString &value,
|
||||
bool editable = true, bool selectable = true)
|
||||
{
|
||||
item->setData(value, Qt::EditRole);
|
||||
item->setFlags((Qt::ItemFlags)(Qt::ItemIsEnabled |
|
||||
(selectable ? Qt::ItemIsSelectable : 0) |
|
||||
(editable ? (Qt::ItemIsEditable) : 0)));
|
||||
}
|
||||
|
||||
static QStandardItem *emptyItem()
|
||||
{
|
||||
auto *item = new QStandardItem();
|
||||
item->setFlags((Qt::ItemFlags)0);
|
||||
return item;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <QStandardItem>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static void setBoolItem(QStandardItem *item, bool value,
|
||||
bool userCheckable = true, bool selectable = true)
|
||||
{
|
||||
item->setFlags((Qt::ItemFlags)(
|
||||
Qt::ItemIsEnabled | (selectable ? Qt::ItemIsSelectable : 0) |
|
||||
(userCheckable ? Qt::ItemIsUserCheckable : 0)));
|
||||
item->setCheckState(value ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
|
||||
static void setStringItem(QStandardItem *item, const QString &value,
|
||||
bool editable = true, bool selectable = true)
|
||||
{
|
||||
item->setData(value, Qt::EditRole);
|
||||
item->setFlags((Qt::ItemFlags)(Qt::ItemIsEnabled |
|
||||
(selectable ? Qt::ItemIsSelectable : 0) |
|
||||
(editable ? (Qt::ItemIsEditable) : 0)));
|
||||
}
|
||||
|
||||
static QStandardItem *emptyItem()
|
||||
{
|
||||
auto *item = new QStandardItem();
|
||||
item->setFlags((Qt::ItemFlags)0);
|
||||
return item;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+22
-22
@@ -1,22 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
typename Container::iterator find_if(Container &container,
|
||||
UnaryPredicate pred)
|
||||
{
|
||||
return std::find_if(container.begin(), container.end(), pred);
|
||||
}
|
||||
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
bool any_of(Container &container, UnaryPredicate pred)
|
||||
{
|
||||
return std::any_of(container.begin(), container.end(), pred);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
typename Container::iterator find_if(Container &container,
|
||||
UnaryPredicate pred)
|
||||
{
|
||||
return std::find_if(container.begin(), container.end(), pred);
|
||||
}
|
||||
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
bool any_of(Container &container, UnaryPredicate pred)
|
||||
{
|
||||
return std::any_of(container.begin(), container.end(), pred);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user