moved more stuff into appbase

This commit is contained in:
fourtf 2018-11-25 21:14:42 +01:00
parent 0b94d0f763
commit 52dcc2130e
19 changed files with 27 additions and 452 deletions

View file

@ -206,14 +206,12 @@ SOURCES += \
src/widgets/splits/ClosedSplits.cpp \
src/providers/ffz/FfzModBadge.cpp \
src/widgets/settingspages/GeneralPage.cpp \
src/util/FuzzyConvert.cpp
HEADERS += \
src/Application.hpp \
src/common/Channel.hpp \
src/common/Common.hpp \
src/common/CompletionModel.hpp \
src/common/FlagsEnum.hpp \
src/common/Atomic.hpp \
src/common/NetworkCommon.hpp \
src/common/NetworkData.hpp \
@ -282,10 +280,8 @@ HEADERS += \
src/singletons/helper/LoggingChannel.hpp \
src/controllers/moderationactions/ModerationAction.hpp \
src/singletons/WindowManager.hpp \
src/util/CombinePath.hpp \
src/util/ConcurrentMap.hpp \
src/util/DebugCount.hpp \
src/util/DistanceBetweenPoints.hpp \
src/util/IrcHelpers.hpp \
src/util/LayoutCreator.hpp \
src/util/QStringHash.hpp \
@ -365,7 +361,6 @@ HEADERS += \
src/providers/twitch/TwitchApi.hpp \
src/messages/Emote.hpp \
src/messages/ImageSet.hpp \
src/common/Outcome.hpp \
src/providers/bttv/BttvEmotes.hpp \
src/providers/LinkResolver.hpp \
src/providers/ffz/FfzEmotes.hpp \
@ -383,7 +378,6 @@ HEADERS += \
src/controllers/notifications/NotificationModel.hpp \
src/singletons/Toasts.hpp \
src/common/DownloadManager.hpp \
src/util/LayoutHelper.hpp \
src/messages/MessageContainer.hpp \
src/common/UsernameSet.hpp \
src/widgets/settingspages/AdvancedPage.hpp \
@ -391,7 +385,6 @@ HEADERS += \
src/widgets/splits/ClosedSplits.hpp \
src/providers/ffz/FfzModBadge.hpp \
src/widgets/settingspages/GeneralPage.hpp \
src/util/FuzzyConvert.hpp
RESOURCES += \
resources/resources.qrc \

@ -1 +1 @@
Subproject commit a830d3692bdbe53b79f244cf1d4695e2a49fb7ed
Subproject commit 6b588cb381334417fb82f4829894ae26d0366588

View file

@ -1,82 +0,0 @@
#pragma once
#include <type_traits>
namespace chatterino {
template <typename T, typename Q = typename std::underlying_type<T>::type>
class FlagsEnum
{
public:
FlagsEnum()
: value_(static_cast<T>(0))
{
}
FlagsEnum(T value)
: value_(value)
{
}
FlagsEnum(std::initializer_list<T> flags)
{
for (auto flag : flags)
{
this->set(flag);
}
}
bool operator==(const FlagsEnum<T> &other)
{
return this->value_ == other.value_;
}
bool operator!=(const FlagsEnum &other)
{
return this->value_ != other.value_;
}
void set(T flag)
{
reinterpret_cast<Q &>(this->value_) |= static_cast<Q>(flag);
}
void unset(T flag)
{
reinterpret_cast<Q &>(this->value_) &= ~static_cast<Q>(flag);
}
void set(T flag, bool value)
{
if (value)
this->set(flag);
else
this->unset(flag);
}
bool has(T flag) const
{
return static_cast<Q>(this->value_) & static_cast<Q>(flag);
}
bool hasAny(FlagsEnum flags) const
{
return static_cast<Q>(this->value_) & static_cast<Q>(flags.value_);
}
bool hasAll(FlagsEnum<T> flags) const
{
return (static_cast<Q>(this->value_) & static_cast<Q>(flags.value_)) &&
static_cast<Q>(flags->value);
}
bool hasNone(std::initializer_list<T> flags) const
{
return !this->hasAny(flags);
}
private:
T value_{};
};
} // namespace chatterino

View file

@ -1,51 +0,0 @@
#pragma once
namespace chatterino {
struct SuccessTag {
};
struct FailureTag {
};
const SuccessTag Success{};
const FailureTag Failure{};
class Outcome
{
public:
Outcome(SuccessTag)
: success_(true)
{
}
Outcome(FailureTag)
: success_(false)
{
}
explicit operator bool() const
{
return this->success_;
}
bool operator!() const
{
return !this->success_;
}
bool operator==(const Outcome &other) const
{
return this->success_ == other.success_;
}
bool operator!=(const Outcome &other) const
{
return !this->operator==(other);
}
private:
bool success_;
};
} // namespace chatterino

View file

@ -193,3 +193,7 @@ private:
};
} // namespace chatterino
#ifdef CHATTERINO
# include "singletons/Settings.hpp"
#endif

View file

@ -32,9 +32,6 @@ namespace chatterino {
using SplitNode = SplitContainer::Node;
using SplitDirection = SplitContainer::Direction;
const int WindowManager::uiScaleMin = -5;
const int WindowManager::uiScaleMax = 10;
void WindowManager::showSettingsDialog(SettingsDialogPreference preference)
{
QTimer::singleShot(
@ -625,55 +622,4 @@ void WindowManager::incGeneration()
this->generation_++;
}
int WindowManager::clampUiScale(int scale)
{
return clamp(scale, uiScaleMin, uiScaleMax);
}
float WindowManager::getUiScaleValue()
{
return getUiScaleValue(getSettings()->uiScale.getValue());
}
float WindowManager::getUiScaleValue(int scale)
{
switch (clampUiScale(scale))
{
case -5:
return 0.5f;
case -4:
return 0.6f;
case -3:
return 0.7f;
case -2:
return 0.8f;
case -1:
return 0.9f;
case 0:
return 1;
case 1:
return 1.2f;
case 2:
return 1.4f;
case 3:
return 1.6f;
case 4:
return 1.8f;
case 5:
return 2;
case 6:
return 2.33f;
case 7:
return 2.66f;
case 8:
return 3;
case 9:
return 3.5f;
case 10:
return 4;
default:
assert(false);
}
}
} // namespace chatterino

View file

@ -27,13 +27,6 @@ public:
static void encodeChannel(IndirectChannel channel, QJsonObject &obj);
static IndirectChannel decodeChannel(const QJsonObject &obj);
static int clampUiScale(int scale);
static float getUiScaleValue();
static float getUiScaleValue(int scale);
static const int uiScaleMin;
static const int uiScaleMax;
void showSettingsDialog(
SettingsDialogPreference preference = SettingsDialogPreference());

View file

@ -1,14 +0,0 @@
#pragma once
#include <QDir>
#include <QString>
namespace chatterino {
// https://stackoverflow.com/a/13014491
inline QString combinePath(const QString &a, const QString &b)
{
return QDir::cleanPath(a + QDir::separator() + b);
}
} // namespace chatterino

View file

@ -1,20 +0,0 @@
#pragma once
#include <QPointF>
#include <cmath>
namespace chatterino {
inline float distanceBetweenPoints(const QPointF &p1, const QPointF &p2)
{
QPointF tmp = p1 - p2;
float distance = 0.f;
distance += tmp.x() * tmp.x();
distance += tmp.y() * tmp.y();
return sqrt(distance);
}
} // namespace chatterino

View file

@ -1,33 +0,0 @@
#include "FuzzyConvert.hpp"
#include <QRegularExpression>
namespace chatterino {
int fuzzyToInt(const QString &str, int default_)
{
static auto intFinder = QRegularExpression("[0-9]+");
auto match = intFinder.match(str);
if (match.hasMatch())
{
return match.captured().toInt();
}
return default_;
}
float fuzzyToFloat(const QString &str, float default_)
{
static auto floatFinder = QRegularExpression("[0-9]+(\\.[0-9]+)?");
auto match = floatFinder.match(str);
if (match.hasMatch())
{
return match.captured().toFloat();
}
return default_;
}
} // namespace chatterino

View file

@ -1,10 +0,0 @@
#pragma once
#include <QString>
namespace chatterino {
int fuzzyToInt(const QString &str, int default_);
float fuzzyToFloat(const QString &str, float default_);
} // namespace chatterino

View file

@ -1,42 +0,0 @@
#pragma once
#include <QLayout>
#include <QWidget>
#include <boost/variant.hpp>
namespace chatterino {
using LayoutItem = boost::variant<QWidget *, QLayout *>;
template <typename T>
T *makeLayout(std::initializer_list<LayoutItem> items)
{
auto t = new T;
for (auto &item : items)
{
switch (item.which())
{
case 0:
t->addItem(new QWidgetItem(boost::get<QWidget *>(item)));
break;
case 1:
t->addItem(boost::get<QLayout *>(item));
break;
}
}
return t;
}
template <typename T, typename With>
T *makeWidget(With with)
{
auto t = new T;
with(t);
return t;
}
} // namespace chatterino

View file

@ -9,6 +9,7 @@
#include "singletons/Updates.hpp"
#include "singletons/WindowManager.hpp"
#include "util/InitUpdateButton.hpp"
#include "util/Shortcut.hpp"
#include "widgets/AccountSwitchPopupWidget.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
@ -16,7 +17,6 @@
#include "widgets/dialogs/WelcomeDialog.hpp"
#include "widgets/helper/EffectLabel.hpp"
#include "widgets/helper/NotebookTab.hpp"
#include "util/Shortcut.hpp"
#include "widgets/helper/TitlebarButton.hpp"
#include "widgets/splits/ClosedSplits.hpp"
#include "widgets/splits/Split.hpp"
@ -289,8 +289,8 @@ void Window::addShortcuts()
auto s = new QShortcut(QKeySequence::ZoomIn, this);
s->setContext(Qt::WindowShortcut);
QObject::connect(s, &QShortcut::activated, this, [] {
getSettings()->uiScale.setValue(WindowManager::clampUiScale(
getSettings()->uiScale.getValue() + 1));
getSettings()->setClampedUiScale(
getSettings()->getClampedUiScale() + 0.1f);
});
}
@ -299,8 +299,8 @@ void Window::addShortcuts()
auto s = new QShortcut(QKeySequence::ZoomOut, this);
s->setContext(Qt::WindowShortcut);
QObject::connect(s, &QShortcut::activated, this, [] {
getSettings()->uiScale.setValue(WindowManager::clampUiScale(
getSettings()->uiScale.getValue() - 1));
getSettings()->setClampedUiScale(
getSettings()->getClampedUiScale() - 0.1f);
});
}

View file

@ -1,45 +0,0 @@
#include "widgets/helper/EffectLabel.hpp"
#include "singletons/Theme.hpp"
#include "widgets/splits/SplitHeader.hpp"
#include <QBrush>
#include <QPainter>
namespace chatterino {
EffectLabel::EffectLabel(BaseWidget *parent, int spacing)
: Button(parent)
, label_(this)
{
setLayout(&this->hbox_);
this->label_.setAlignment(Qt::AlignCenter);
this->hbox_.setMargin(0);
this->hbox_.addSpacing(spacing);
this->hbox_.addWidget(&this->label_);
this->hbox_.addSpacing(spacing);
}
EffectLabel2::EffectLabel2(BaseWidget *parent, int padding)
: Button(parent)
, label_(this)
{
auto *hbox = new QHBoxLayout(this);
this->setLayout(hbox);
// this->label_.setAlignment(Qt::AlignCenter);
this->label_.setCentered(true);
hbox->setMargin(0);
// hbox.addSpacing(spacing);
hbox->addWidget(&this->label_);
// hbox.addSpacing(spacing);
}
Label &EffectLabel2::getLabel()
{
return this->label_;
}
} // namespace chatterino

View file

@ -1,41 +0,0 @@
#pragma once
#include "widgets/BaseWidget.hpp"
#include "widgets/Label.hpp"
#include "widgets/helper/Button.hpp"
#include "widgets/helper/SignalLabel.hpp"
#include <QHBoxLayout>
#include <QLabel>
#include <QPaintEvent>
#include <QWidget>
namespace chatterino {
class EffectLabel : public Button
{
public:
explicit EffectLabel(BaseWidget *parent = nullptr, int spacing = 6);
SignalLabel &getLabel()
{
return this->label_;
}
private:
QHBoxLayout hbox_;
SignalLabel label_;
};
class EffectLabel2 : public Button
{
public:
explicit EffectLabel2(BaseWidget *parent = nullptr, int padding = 6);
Label &getLabel();
private:
Label label_;
};
} // namespace chatterino

View file

@ -100,7 +100,14 @@ void NotebookTab::updateSize()
width = (metrics.width(this->getTitle()) + int(16 * scale));
}
width = clamp(width, this->height(), int(150 * scale));
if (this->height() > 150 * scale)
{
width = this->height();
}
else
{
width = clamp(width, this->height(), int(150 * scale));
}
auto height = int(NOTEBOOK_TAB_HEIGHT * scale);
if (this->width() != width || this->height() != height)

View file

@ -158,12 +158,18 @@ void GeneralPage::initLayout(SettingsLayout &layout)
getApp()->fonts->chatFontSize,
[](auto val) { return QString::number(val) + "pt"; },
[](auto args) { return fuzzyToInt(args.value, 10); });
layout.addDropdown<int>(
layout.addDropdown<float>(
"UI Scale",
{"0.5x", "0.6x", "0.7x", "0.8x", "0.9x", "Default", "1.2x", "1.4x",
"1.6x", "1.8x", "2x", "2.33x", "2.66x", "3x", "3.5x", "4x"},
s.uiScale, [](auto val) { return val + 5; },
[](auto args) { return args.index - 5; }, false);
s.uiScale,
[](auto val) {
if (val == 1)
return QString("Default");
else
return QString::number(val) + "x";
},
[](auto args) { return fuzzyToFloat(args.value, 1.f); });
layout.addCheckbox("Always on top", s.windowTopMost);
layout.addTitle("Interface");

View file

@ -125,13 +125,6 @@ void LookPage::addInterfaceTab(LayoutCreator<QVBoxLayout> layout)
box->addStretch(1);
}
// ui scale
{
auto box = layout.emplace<QHBoxLayout>().withoutMargin();
box.emplace<QLabel>("Window scale: ");
box.append(this->createUiScaleSlider());
}
layout.append(
this->createCheckBox(WINDOW_TOPMOST, getSettings()->windowTopMost));
@ -567,34 +560,6 @@ QLayout *LookPage::createFontChanger()
return layout;
}
QLayout *LookPage::createUiScaleSlider()
{
auto layout = new QHBoxLayout();
auto slider = new QSlider(Qt::Horizontal);
auto label = new QLabel();
layout->addWidget(slider);
layout->addWidget(label);
slider->setMinimum(WindowManager::uiScaleMin);
slider->setMaximum(WindowManager::uiScaleMax);
slider->setValue(
WindowManager::clampUiScale(getSettings()->uiScale.getValue()));
label->setMinimumWidth(100);
QObject::connect(slider, &QSlider::valueChanged, [](auto value) {
getSettings()->uiScale.setValue(value);
});
getSettings()->uiScale.connect(
[label](auto, auto) {
label->setText(QString::number(WindowManager::getUiScaleValue()));
},
this->connections_);
return layout;
}
QLayout *LookPage::createBoldScaleSlider()
{
auto layout = new QHBoxLayout();

View file

@ -30,7 +30,6 @@ private:
QLayout *createThemeColorChanger();
QLayout *createFontChanger();
QLayout *createUiScaleSlider();
QLayout *createBoldScaleSlider();
ChannelPtr createPreviewChannel();