Replace boost::optional with std::optional (#4877)
This commit is contained in:
@@ -273,7 +273,7 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr)
|
||||
float scale = 1.f;
|
||||
if (auto dpi = getWindowDpi(attached))
|
||||
{
|
||||
scale = dpi.get() / 96.f;
|
||||
scale = *dpi / 96.f;
|
||||
|
||||
for (auto w : this->ui_.split->findChildren<BaseWidget *>())
|
||||
{
|
||||
|
||||
@@ -42,16 +42,15 @@ float BaseWidget::scale() const
|
||||
{
|
||||
if (this->overrideScale_)
|
||||
{
|
||||
return this->overrideScale_.get();
|
||||
return *this->overrideScale_;
|
||||
}
|
||||
else if (auto baseWidget = dynamic_cast<BaseWidget *>(this->window()))
|
||||
|
||||
if (auto *baseWidget = dynamic_cast<BaseWidget *>(this->window()))
|
||||
{
|
||||
return baseWidget->scale_;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1.f;
|
||||
}
|
||||
|
||||
return 1.F;
|
||||
}
|
||||
|
||||
void BaseWidget::setScale(float value)
|
||||
@@ -65,13 +64,13 @@ void BaseWidget::setScale(float value)
|
||||
this->setScaleIndependantSize(this->scaleIndependantSize());
|
||||
}
|
||||
|
||||
void BaseWidget::setOverrideScale(boost::optional<float> value)
|
||||
void BaseWidget::setOverrideScale(std::optional<float> value)
|
||||
{
|
||||
this->overrideScale_ = value;
|
||||
this->setScale(this->scale());
|
||||
}
|
||||
|
||||
boost::optional<float> BaseWidget::overrideScale() const
|
||||
std::optional<float> BaseWidget::overrideScale() const
|
||||
{
|
||||
return this->overrideScale_;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <QShortcut>
|
||||
#include <QWidget>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Theme;
|
||||
@@ -22,8 +23,8 @@ public:
|
||||
virtual float scale() const;
|
||||
pajlada::Signals::Signal<float> scaleChanged;
|
||||
|
||||
boost::optional<float> overrideScale() const;
|
||||
void setOverrideScale(boost::optional<float>);
|
||||
std::optional<float> overrideScale() const;
|
||||
void setOverrideScale(std::optional<float>);
|
||||
|
||||
QSize scaleIndependantSize() const;
|
||||
int scaleIndependantWidth() const;
|
||||
@@ -56,7 +57,7 @@ protected:
|
||||
|
||||
private:
|
||||
float scale_{1.f};
|
||||
boost::optional<float> overrideScale_;
|
||||
std::optional<float> overrideScale_;
|
||||
QSize scaleIndependantSize_;
|
||||
|
||||
std::vector<BaseWidget *> widgets_;
|
||||
|
||||
@@ -728,7 +728,7 @@ bool BaseWindow::handleSHOWWINDOW(MSG *msg)
|
||||
|
||||
if (auto dpi = getWindowDpi(msg->hwnd))
|
||||
{
|
||||
float currentScale = (float)dpi.get() / 96.F;
|
||||
float currentScale = (float)dpi.value() / 96.F;
|
||||
if (currentScale != this->nativeScale_)
|
||||
{
|
||||
this->nativeScale_ = currentScale;
|
||||
|
||||
@@ -95,7 +95,7 @@ protected:
|
||||
|
||||
void updateScale();
|
||||
|
||||
boost::optional<QColor> overrideBackgroundColor_;
|
||||
std::optional<QColor> overrideBackgroundColor_;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
@@ -70,7 +70,7 @@ void FramelessEmbedWindow::showEvent(QShowEvent *)
|
||||
}
|
||||
|
||||
if (auto parentHwnd =
|
||||
reinterpret_cast<HWND>(getArgs().parentWindowId.get()))
|
||||
reinterpret_cast<HWND>(getArgs().parentWindowId.value()))
|
||||
{
|
||||
auto handle = reinterpret_cast<HWND>(this->winId());
|
||||
if (!::SetParent(handle, parentHwnd))
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include "util/DisplayBadge.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
@@ -14,7 +14,7 @@ class BadgePickerDialog : public QDialog,
|
||||
public std::enable_shared_from_this<BadgePickerDialog>
|
||||
{
|
||||
using QIconPtr = std::shared_ptr<QIcon>;
|
||||
using BadgeOpt = boost::optional<DisplayBadge>;
|
||||
using BadgeOpt = std::optional<DisplayBadge>;
|
||||
|
||||
public:
|
||||
BadgePickerDialog(QList<DisplayBadge> badges, QWidget *parent = nullptr);
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#include "providers/irc/Irc2.hpp"
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <QDialog>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace Ui {
|
||||
class IrcConnectionEditor;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ void ReplyThreadPopup::addMessagesFromThread()
|
||||
this->ui_.threadView->setSourceChannel(sourceChannel);
|
||||
|
||||
auto overrideFlags =
|
||||
boost::optional<MessageFlags>(this->thread_->root()->flags);
|
||||
std::optional<MessageFlags>(this->thread_->root()->flags);
|
||||
overrideFlags->set(MessageFlag::DoNotLog);
|
||||
|
||||
this->virtualChannel_->addMessage(this->thread_->root(), overrideFlags);
|
||||
@@ -247,7 +247,7 @@ void ReplyThreadPopup::addMessagesFromThread()
|
||||
{
|
||||
if (auto msg = msgRef.lock())
|
||||
{
|
||||
auto overrideFlags = boost::optional<MessageFlags>(msg->flags);
|
||||
auto overrideFlags = std::optional<MessageFlags>(msg->flags);
|
||||
overrideFlags->set(MessageFlag::DoNotLog);
|
||||
|
||||
this->virtualChannel_->addMessage(msg, overrideFlags);
|
||||
@@ -261,7 +261,7 @@ void ReplyThreadPopup::addMessagesFromThread()
|
||||
if (message->replyThread == this->thread_)
|
||||
{
|
||||
auto overrideFlags =
|
||||
boost::optional<MessageFlags>(message->flags);
|
||||
std::optional<MessageFlags>(message->flags);
|
||||
overrideFlags->set(MessageFlag::DoNotLog);
|
||||
|
||||
// same reply thread, add message
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace {
|
||||
{
|
||||
MessagePtr message = snapshot[i];
|
||||
|
||||
auto overrideFlags = boost::optional<MessageFlags>(message->flags);
|
||||
auto overrideFlags = std::optional<MessageFlags>(message->flags);
|
||||
overrideFlags->set(MessageFlag::DoNotLog);
|
||||
|
||||
if (checkMessageUserName(userName, message))
|
||||
|
||||
@@ -36,7 +36,7 @@ Button::Button(BaseWidget *parent)
|
||||
this->setMouseTracking(true);
|
||||
}
|
||||
|
||||
void Button::setMouseEffectColor(boost::optional<QColor> color)
|
||||
void Button::setMouseEffectColor(std::optional<QColor> color)
|
||||
{
|
||||
this->mouseEffectColor_ = std::move(color);
|
||||
}
|
||||
@@ -185,7 +185,7 @@ void Button::fancyPaint(QPainter &painter)
|
||||
|
||||
if (this->mouseEffectColor_)
|
||||
{
|
||||
c = this->mouseEffectColor_.get();
|
||||
c = *this->mouseEffectColor_;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "widgets/BaseWidget.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
@@ -10,6 +9,8 @@
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Button : public BaseWidget
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
|
||||
Button(BaseWidget *parent = nullptr);
|
||||
|
||||
void setMouseEffectColor(boost::optional<QColor> color);
|
||||
void setMouseEffectColor(std::optional<QColor> color);
|
||||
void setPixmap(const QPixmap &pixmap_);
|
||||
const QPixmap &getPixmap() const;
|
||||
|
||||
@@ -94,7 +95,7 @@ private:
|
||||
double hoverMultiplier_{0.0};
|
||||
QTimer effectTimer_{};
|
||||
std::vector<ClickEffect> clickEffects_{};
|
||||
boost::optional<QColor> mouseEffectColor_{};
|
||||
std::optional<QColor> mouseEffectColor_{};
|
||||
std::unique_ptr<QMenu> menu_{};
|
||||
};
|
||||
|
||||
|
||||
@@ -291,13 +291,12 @@ bool ChannelView::paused() const
|
||||
return this->pausable() && !this->pauses_.empty();
|
||||
}
|
||||
|
||||
void ChannelView::pause(PauseReason reason, boost::optional<uint> msecs)
|
||||
void ChannelView::pause(PauseReason reason, std::optional<uint> msecs)
|
||||
{
|
||||
if (msecs)
|
||||
{
|
||||
/// Msecs has a value
|
||||
auto timePoint =
|
||||
SteadyClock::now() + std::chrono::milliseconds(msecs.get());
|
||||
auto timePoint = SteadyClock::now() + std::chrono::milliseconds(*msecs);
|
||||
auto it = this->pauses_.find(reason);
|
||||
|
||||
if (it == this->pauses_.end())
|
||||
@@ -308,15 +307,19 @@ void ChannelView::pause(PauseReason reason, boost::optional<uint> msecs)
|
||||
else
|
||||
{
|
||||
/// If the new time point is newer then we override.
|
||||
if (it->second && it->second.get() < timePoint)
|
||||
it->second = timePoint;
|
||||
auto &previousTimePoint = it->second;
|
||||
if (previousTimePoint.has_value() &&
|
||||
previousTimePoint.value() < timePoint)
|
||||
{
|
||||
previousTimePoint = timePoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Msecs is none -> pause is infinite.
|
||||
/// We just override the value.
|
||||
this->pauses_[reason] = boost::none;
|
||||
this->pauses_[reason] = std::nullopt;
|
||||
}
|
||||
|
||||
this->updatePauses();
|
||||
@@ -339,7 +342,7 @@ void ChannelView::updatePauses()
|
||||
this->unpaused();
|
||||
|
||||
/// No pauses so we can stop the timer
|
||||
this->pauseEnd_ = boost::none;
|
||||
this->pauseEnd_ = std::nullopt;
|
||||
this->pauseTimer_.stop();
|
||||
|
||||
this->scrollBar_->offsetMaximum(this->pauseScrollMaximumOffset_);
|
||||
@@ -355,7 +358,7 @@ void ChannelView::updatePauses()
|
||||
}))
|
||||
{
|
||||
/// Some of the pauses are infinite
|
||||
this->pauseEnd_ = boost::none;
|
||||
this->pauseEnd_ = std::nullopt;
|
||||
this->pauseTimer_.stop();
|
||||
}
|
||||
else
|
||||
@@ -366,7 +369,7 @@ void ChannelView::updatePauses()
|
||||
[](auto &&a, auto &&b) {
|
||||
return a.second > b.second;
|
||||
})
|
||||
->second.get();
|
||||
->second.value();
|
||||
|
||||
if (pauseEnd != this->pauseEnd_)
|
||||
{
|
||||
@@ -645,13 +648,12 @@ bool ChannelView::getEnableScrollingToBottom() const
|
||||
return this->enableScrollingToBottom_;
|
||||
}
|
||||
|
||||
void ChannelView::setOverrideFlags(boost::optional<MessageElementFlags> value)
|
||||
void ChannelView::setOverrideFlags(std::optional<MessageElementFlags> value)
|
||||
{
|
||||
this->overrideFlags_ = std::move(value);
|
||||
}
|
||||
|
||||
const boost::optional<MessageElementFlags> &ChannelView::getOverrideFlags()
|
||||
const
|
||||
const std::optional<MessageElementFlags> &ChannelView::getOverrideFlags() const
|
||||
{
|
||||
return this->overrideFlags_;
|
||||
}
|
||||
@@ -697,7 +699,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
|
||||
this->channelConnections_.managedConnect(
|
||||
underlyingChannel->messageAppended,
|
||||
[this](MessagePtr &message,
|
||||
boost::optional<MessageFlags> overridingFlags) {
|
||||
std::optional<MessageFlags> overridingFlags) {
|
||||
if (this->shouldIncludeMessage(message))
|
||||
{
|
||||
if (this->channel_->lastDate_ != QDate::currentDate())
|
||||
@@ -713,12 +715,12 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
|
||||
// logging will be handled. Prevent duplications.
|
||||
if (overridingFlags)
|
||||
{
|
||||
overridingFlags.get().set(MessageFlag::DoNotLog);
|
||||
overridingFlags->set(MessageFlag::DoNotLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
overridingFlags = MessageFlags(message->flags);
|
||||
overridingFlags.get().set(MessageFlag::DoNotLog);
|
||||
overridingFlags->set(MessageFlag::DoNotLog);
|
||||
}
|
||||
|
||||
this->channel_->addMessage(message, overridingFlags);
|
||||
@@ -764,7 +766,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
|
||||
this->channelConnections_.managedConnect(
|
||||
this->channel_->messageAppended,
|
||||
[this](MessagePtr &message,
|
||||
boost::optional<MessageFlags> overridingFlags) {
|
||||
std::optional<MessageFlags> overridingFlags) {
|
||||
this->messageAppended(message, std::move(overridingFlags));
|
||||
});
|
||||
|
||||
@@ -880,12 +882,12 @@ bool ChannelView::hasSourceChannel() const
|
||||
}
|
||||
|
||||
void ChannelView::messageAppended(MessagePtr &message,
|
||||
boost::optional<MessageFlags> overridingFlags)
|
||||
std::optional<MessageFlags> overridingFlags)
|
||||
{
|
||||
auto *messageFlags = &message->flags;
|
||||
if (overridingFlags)
|
||||
{
|
||||
messageFlags = overridingFlags.get_ptr();
|
||||
messageFlags = &*overridingFlags;
|
||||
}
|
||||
|
||||
auto messageRef = std::make_shared<MessageLayout>(message);
|
||||
@@ -1109,7 +1111,7 @@ MessageElementFlags ChannelView::getFlags() const
|
||||
|
||||
if (this->overrideFlags_)
|
||||
{
|
||||
return this->overrideFlags_.get();
|
||||
return *this->overrideFlags_;
|
||||
}
|
||||
|
||||
MessageElementFlags flags = app->windows->getWordFlags();
|
||||
|
||||
@@ -93,8 +93,8 @@ public:
|
||||
|
||||
void setEnableScrollingToBottom(bool);
|
||||
bool getEnableScrollingToBottom() const;
|
||||
void setOverrideFlags(boost::optional<MessageElementFlags> value);
|
||||
const boost::optional<MessageElementFlags> &getOverrideFlags() const;
|
||||
void setOverrideFlags(std::optional<MessageElementFlags> value);
|
||||
const std::optional<MessageElementFlags> &getOverrideFlags() const;
|
||||
void updateLastReadMessage();
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
bool pausable() const;
|
||||
void setPausable(bool value);
|
||||
bool paused() const;
|
||||
void pause(PauseReason reason, boost::optional<uint> msecs = boost::none);
|
||||
void pause(PauseReason reason, std::optional<uint> msecs = std::nullopt);
|
||||
void unpause(PauseReason reason);
|
||||
|
||||
MessageElementFlags getFlags() const;
|
||||
@@ -195,7 +195,7 @@ private:
|
||||
void initializeSignals();
|
||||
|
||||
void messageAppended(MessagePtr &message,
|
||||
boost::optional<MessageFlags> overridingFlags);
|
||||
std::optional<MessageFlags> overridingFlags);
|
||||
void messageAddedAtStart(std::vector<MessagePtr> &messages);
|
||||
void messageRemoveFromStart(MessagePtr &message);
|
||||
void messageReplaced(size_t index, MessagePtr &replacement);
|
||||
@@ -265,15 +265,15 @@ private:
|
||||
|
||||
bool pausable_ = false;
|
||||
QTimer pauseTimer_;
|
||||
std::unordered_map<PauseReason, boost::optional<SteadyClock::time_point>>
|
||||
std::unordered_map<PauseReason, std::optional<SteadyClock::time_point>>
|
||||
pauses_;
|
||||
boost::optional<SteadyClock::time_point> pauseEnd_;
|
||||
std::optional<SteadyClock::time_point> pauseEnd_;
|
||||
int pauseScrollMinimumOffset_ = 0;
|
||||
int pauseScrollMaximumOffset_ = 0;
|
||||
// Keeps track how many message indices we need to offset the selection when we resume scrolling
|
||||
uint32_t pauseSelectionOffset_ = 0;
|
||||
|
||||
boost::optional<MessageElementFlags> overrideFlags_;
|
||||
std::optional<MessageElementFlags> overrideFlags_;
|
||||
MessageLayoutPtr lastReadMessage_;
|
||||
|
||||
ThreadGuard snapshotGuard_;
|
||||
|
||||
@@ -52,7 +52,7 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName,
|
||||
// If all predicates match, add the message to the channel
|
||||
if (accept)
|
||||
{
|
||||
auto overrideFlags = boost::optional<MessageFlags>(message->flags);
|
||||
auto overrideFlags = std::optional<MessageFlags>(message->flags);
|
||||
overrideFlags->set(MessageFlag::DoNotLog);
|
||||
|
||||
channel->addMessage(message, overrideFlags);
|
||||
|
||||
Reference in New Issue
Block a user