Fix merge conflicts

This commit is contained in:
Leon Richardt 2019-09-08 22:58:17 +02:00
commit b6f632701f
15 changed files with 74 additions and 65 deletions

View file

@ -44,12 +44,12 @@
namespace AB_NAMESPACE { namespace AB_NAMESPACE {
BaseWindow::BaseWindow(QWidget *parent, Flags _flags) BaseWindow::BaseWindow(FlagsEnum<Flags> _flags, QWidget *parent)
: BaseWidget(parent, : BaseWidget(parent,
Qt::Window | ((_flags & TopMost) ? Qt::WindowStaysOnTopHint Qt::Window | (_flags.has(TopMost) ? Qt::WindowStaysOnTopHint
: Qt::WindowFlags())) : Qt::WindowFlags()))
, enableCustomFrame_(_flags & EnableCustomFrame) , enableCustomFrame_(_flags.has(EnableCustomFrame))
, frameless_(_flags & Frameless) , frameless_(_flags.has(Frameless))
, flags_(_flags) , flags_(_flags)
{ {
if (this->frameless_) if (this->frameless_)
@ -74,8 +74,6 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
createWindowShortcut(this, "CTRL+0", createWindowShortcut(this, "CTRL+0",
[] { getSettings()->uiScale.setValue(1); }); [] { getSettings()->uiScale.setValue(1); });
// QTimer::this->scaleChangedEvent(this->getScale());
this->resize(300, 150); this->resize(300, 150);
#ifdef USEWINSDK #ifdef USEWINSDK
@ -113,11 +111,6 @@ float BaseWindow::qtFontScale() const
return this->scale() / this->nativeScale_; return this->scale() / this->nativeScale_;
} }
BaseWindow::Flags BaseWindow::getFlags()
{
return this->flags_;
}
void BaseWindow::init() void BaseWindow::init()
{ {
this->setWindowIcon(QIcon(":/images/icon.png")); this->setWindowIcon(QIcon(":/images/icon.png"));
@ -206,7 +199,7 @@ void BaseWindow::init()
#ifdef USEWINSDK #ifdef USEWINSDK
// fourtf: don't ask me why we need to delay this // fourtf: don't ask me why we need to delay this
if (!(this->flags_ & Flags::TopMost)) if (!this->flags_.has(TopMost))
{ {
QTimer::singleShot(1, this, [this] { QTimer::singleShot(1, this, [this] {
getSettings()->windowTopMost.connect( getSettings()->windowTopMost.connect(
@ -370,7 +363,7 @@ void BaseWindow::onFocusLost()
void BaseWindow::mousePressEvent(QMouseEvent *event) void BaseWindow::mousePressEvent(QMouseEvent *event)
{ {
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
if (this->flags_ & FramelessDraggable) if (this->flags_.has(FramelessDraggable))
{ {
this->movingRelativePos = event->localPos(); this->movingRelativePos = event->localPos();
if (auto widget = if (auto widget =
@ -406,7 +399,7 @@ void BaseWindow::mousePressEvent(QMouseEvent *event)
void BaseWindow::mouseReleaseEvent(QMouseEvent *event) void BaseWindow::mouseReleaseEvent(QMouseEvent *event)
{ {
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
if (this->flags_ & FramelessDraggable) if (this->flags_.has(FramelessDraggable))
{ {
if (this->moving) if (this->moving)
{ {
@ -422,7 +415,7 @@ void BaseWindow::mouseReleaseEvent(QMouseEvent *event)
void BaseWindow::mouseMoveEvent(QMouseEvent *event) void BaseWindow::mouseMoveEvent(QMouseEvent *event)
{ {
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
if (this->flags_ & FramelessDraggable) if (this->flags_.has(FramelessDraggable))
{ {
if (this->moving) if (this->moving)
{ {
@ -541,6 +534,18 @@ void BaseWindow::closeEvent(QCloseEvent *)
this->closing.invoke(); this->closing.invoke();
} }
void BaseWindow::showEvent(QShowEvent *)
{
if (this->frameless_)
{
this->moveIntoDesktopRect(this);
qDebug() << "show";
QTimer::singleShot(30, this,
[this] { this->moveIntoDesktopRect(this); });
}
}
void BaseWindow::moveIntoDesktopRect(QWidget *parent) void BaseWindow::moveIntoDesktopRect(QWidget *parent)
{ {
if (!this->stayInScreenRect_) if (!this->stayInScreenRect_)
@ -649,7 +654,7 @@ void BaseWindow::paintEvent(QPaintEvent *)
void BaseWindow::updateScale() void BaseWindow::updateScale()
{ {
auto scale = auto scale =
this->nativeScale_ * (this->flags_ & DisableCustomScaling this->nativeScale_ * (this->flags_.has(DisableCustomScaling)
? 1 ? 1
: getABSettings()->getClampedUiScale()); : getABSettings()->getClampedUiScale());
@ -708,17 +713,11 @@ bool BaseWindow::handleDPICHANGED(MSG *msg)
float _scale = dpi / 96.f; float _scale = dpi / 96.f;
static bool firstResize = true; auto *prcNewWindow = reinterpret_cast<RECT *>(msg->lParam);
SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
if (!firstResize) prcNewWindow->right - prcNewWindow->left,
{ prcNewWindow->bottom - prcNewWindow->top,
auto *prcNewWindow = reinterpret_cast<RECT *>(msg->lParam); SWP_NOZORDER | SWP_NOACTIVATE);
SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
prcNewWindow->right - prcNewWindow->left,
prcNewWindow->bottom - prcNewWindow->top,
SWP_NOZORDER | SWP_NOACTIVATE);
}
firstResize = false;
this->nativeScale_ = _scale; this->nativeScale_ = _scale;
this->updateScale(); this->updateScale();
@ -953,7 +952,7 @@ bool BaseWindow::handleNCHITTEST(MSG *msg, long *result)
return true; return true;
} }
else if (this->flags_ & FramelessDraggable) else if (this->flags_.has(FramelessDraggable))
{ {
*result = 0; *result = 0;
bool client = false; bool client = false;

View file

@ -4,6 +4,7 @@
#include <functional> #include <functional>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
#include "common/FlagsEnum.hpp"
class QHBoxLayout; class QHBoxLayout;
struct tagMSG; struct tagMSG;
@ -32,7 +33,8 @@ public:
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide }; enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None); explicit BaseWindow(FlagsEnum<Flags> flags_ = None,
QWidget *parent = nullptr);
void setInitialBounds(const QRect &bounds); void setInitialBounds(const QRect &bounds);
QRect getBounds(); QRect getBounds();
@ -54,8 +56,6 @@ public:
virtual float scale() const override; virtual float scale() const override;
float qtFontScale() const; float qtFontScale() const;
Flags getFlags();
pajlada::Signals::NoArgSignal closing; pajlada::Signals::NoArgSignal closing;
static bool supportsCustomWindowFrame(); static bool supportsCustomWindowFrame();
@ -72,6 +72,7 @@ protected:
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
virtual void moveEvent(QMoveEvent *) override; virtual void moveEvent(QMoveEvent *) override;
virtual void closeEvent(QCloseEvent *) override; virtual void closeEvent(QCloseEvent *) override;
virtual void showEvent(QShowEvent *) override;
virtual void themeChangedEvent() override; virtual void themeChangedEvent() override;
virtual bool event(QEvent *event) override; virtual bool event(QEvent *event) override;
@ -106,7 +107,7 @@ private:
bool frameless_; bool frameless_;
bool stayInScreenRect_ = false; bool stayInScreenRect_ = false;
bool shown_ = false; bool shown_ = false;
Flags flags_; FlagsEnum<Flags> flags_;
float nativeScale_ = 1; float nativeScale_ = 1;
struct { struct {

View file

@ -21,7 +21,7 @@ TooltipWidget *TooltipWidget::getInstance()
} }
TooltipWidget::TooltipWidget(BaseWidget *parent) TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow(parent, BaseWindow::TopMost) : BaseWindow(BaseWindow::TopMost, parent)
, displayImage_(new QLabel()) , displayImage_(new QLabel())
, displayText_(new QLabel()) , displayText_(new QLabel())
{ {

View file

@ -143,9 +143,21 @@ bool TwitchMessageBuilder::isIgnored() const
return false; return false;
} }
inline QMediaPlayer *getPlayer()
{
if (isGuiThread())
{
static auto player = new QMediaPlayer;
return player;
}
else
{
return nullptr;
}
}
void TwitchMessageBuilder::triggerHighlights() void TwitchMessageBuilder::triggerHighlights()
{ {
static auto player = new QMediaPlayer;
static QUrl currentPlayerUrl; static QUrl currentPlayerUrl;
if (this->historicalMessage_) if (this->historicalMessage_)
@ -165,21 +177,24 @@ void TwitchMessageBuilder::triggerHighlights()
if (this->highlightSound_ && resolveFocus) if (this->highlightSound_ && resolveFocus)
{ {
// update the media player url if necessary if (auto player = getPlayer())
QUrl highlightSoundUrl =
getSettings()->customHighlightSound
? QUrl::fromLocalFile(
getSettings()->pathHighlightSound.getValue())
: QUrl("qrc:/sounds/ping2.wav");
if (currentPlayerUrl != highlightSoundUrl)
{ {
player->setMedia(highlightSoundUrl); // update the media player url if necessary
QUrl highlightSoundUrl =
getSettings()->customHighlightSound
? QUrl::fromLocalFile(
getSettings()->pathHighlightSound.getValue())
: QUrl("qrc:/sounds/ping2.wav");
currentPlayerUrl = highlightSoundUrl; if (currentPlayerUrl != highlightSoundUrl)
{
player->setMedia(highlightSoundUrl);
currentPlayerUrl = highlightSoundUrl;
}
player->play();
} }
player->play();
} }
if (this->highlightAlert_) if (this->highlightAlert_)

View file

@ -80,7 +80,6 @@ void WindowManager::showAccountSelectPopup(QPoint point)
QPoint buttonPos = point; QPoint buttonPos = point;
w->move(buttonPos.x() - 30, buttonPos.y()); w->move(buttonPos.x() - 30, buttonPos.y());
w->show(); w->show();
w->setFocus(); w->setFocus();
} }

View file

@ -11,8 +11,7 @@
namespace chatterino { namespace chatterino {
AccountSwitchPopup::AccountSwitchPopup(QWidget *parent) AccountSwitchPopup::AccountSwitchPopup(QWidget *parent)
: BaseWindow(parent, : BaseWindow({BaseWindow::TopMost, BaseWindow::Frameless}, parent)
BaseWindow::Flags(BaseWindow::TopMost | BaseWindow::Frameless))
{ {
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
this->setWindowFlag(Qt::Popup); this->setWindowFlag(Qt::Popup);
@ -25,8 +24,6 @@ AccountSwitchPopup::AccountSwitchPopup(QWidget *parent)
this->ui_.accountSwitchWidget->setFocusPolicy(Qt::NoFocus); this->ui_.accountSwitchWidget->setFocusPolicy(Qt::NoFocus);
vbox->addWidget(this->ui_.accountSwitchWidget); vbox->addWidget(this->ui_.accountSwitchWidget);
// vbox->setSizeConstraint(QLayout::SetMinimumSize);
auto hbox = new QHBoxLayout(); auto hbox = new QHBoxLayout();
auto manageAccountsButton = new QPushButton(this); auto manageAccountsButton = new QPushButton(this);
manageAccountsButton->setText("Manage Accounts"); manageAccountsButton->setText("Manage Accounts");

View file

@ -39,7 +39,7 @@
namespace chatterino { namespace chatterino {
Window::Window(WindowType type) Window::Window(WindowType type)
: BaseWindow(nullptr, BaseWindow::EnableCustomFrame) : BaseWindow(BaseWindow::EnableCustomFrame)
, type_(type) , type_(type)
, notebook_(new SplitNotebook(this)) , notebook_(new SplitNotebook(this))
{ {

View file

@ -101,7 +101,7 @@ namespace {
} // namespace } // namespace
EmotePopup::EmotePopup(QWidget *parent) EmotePopup::EmotePopup(QWidget *parent)
: BaseWindow(parent, BaseWindow::EnableCustomFrame) : BaseWindow(BaseWindow::EnableCustomFrame, parent)
{ {
auto layout = new QVBoxLayout(this); auto layout = new QVBoxLayout(this);
this->getLayoutContainer()->setLayout(layout); this->getLayoutContainer()->setLayout(layout);

View file

@ -11,7 +11,7 @@
namespace chatterino { namespace chatterino {
NotificationPopup::NotificationPopup() NotificationPopup::NotificationPopup()
: BaseWindow((QWidget *)nullptr, BaseWindow::Frameless) : BaseWindow(BaseWindow::Frameless)
, channel_(std::make_shared<Channel>("notifications", Channel::Type::None)) , channel_(std::make_shared<Channel>("notifications", Channel::Type::None))
{ {

View file

@ -19,7 +19,7 @@
namespace chatterino { namespace chatterino {
SelectChannelDialog::SelectChannelDialog(QWidget *parent) SelectChannelDialog::SelectChannelDialog(QWidget *parent)
: BaseWindow(parent, BaseWindow::EnableCustomFrame) : BaseWindow(BaseWindow::EnableCustomFrame, parent)
, selectedChannel_(Channel::getEmpty()) , selectedChannel_(Channel::getEmpty())
{ {
this->setWindowTitle("Select a channel to join"); this->setWindowTitle("Select a channel to join");

View file

@ -24,7 +24,7 @@ namespace chatterino {
SettingsDialog *SettingsDialog::handle = nullptr; SettingsDialog *SettingsDialog::handle = nullptr;
SettingsDialog::SettingsDialog() SettingsDialog::SettingsDialog()
: BaseWindow(nullptr, BaseWindow::DisableCustomScaling) : BaseWindow(BaseWindow::DisableCustomScaling)
{ {
this->setWindowTitle("Chatterino Settings"); this->setWindowTitle("Chatterino Settings");
@ -41,7 +41,7 @@ SettingsDialog::SettingsDialog()
void SettingsDialog::initUi() void SettingsDialog::initUi()
{ {
auto outerBox = LayoutCreator<SettingsDialog>(this) auto outerBox = LayoutCreator<QWidget>(this->getLayoutContainer())
.setLayoutType<QVBoxLayout>() .setLayoutType<QVBoxLayout>()
.withoutSpacing(); .withoutSpacing();

View file

@ -11,9 +11,8 @@
namespace chatterino { namespace chatterino {
UpdateDialog::UpdateDialog() UpdateDialog::UpdateDialog()
: BaseWindow(nullptr, : BaseWindow({BaseWindow::Frameless, BaseWindow::TopMost,
BaseWindow::Flags(BaseWindow::Frameless | BaseWindow::TopMost | BaseWindow::EnableCustomFrame})
BaseWindow::EnableCustomFrame))
{ {
auto layout = auto layout =
LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>(); LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>();

View file

@ -43,8 +43,7 @@ namespace {
} // namespace } // namespace
UserInfoPopup::UserInfoPopup() UserInfoPopup::UserInfoPopup()
: BaseWindow(nullptr, BaseWindow::Flags(BaseWindow::Frameless | : BaseWindow({BaseWindow::Frameless, BaseWindow::FramelessDraggable})
BaseWindow::FramelessDraggable))
, hack_(new bool) , hack_(new bool)
{ {
this->setStayInScreenRect(true); this->setStayInScreenRect(true);

View file

@ -3,7 +3,7 @@
namespace chatterino { namespace chatterino {
WelcomeDialog::WelcomeDialog() WelcomeDialog::WelcomeDialog()
: BaseWindow(nullptr, BaseWindow::EnableCustomFrame) : BaseWindow(BaseWindow::EnableCustomFrame)
{ {
this->setWindowTitle("Chatterino quick setup"); this->setWindowTitle("Chatterino quick setup");
} }

View file

@ -52,7 +52,7 @@ namespace {
const QString &title, const QString &description) const QString &title, const QString &description)
{ {
auto window = auto window =
new BaseWindow(parent, BaseWindow::Flags::EnableCustomFrame); new BaseWindow(BaseWindow::Flags::EnableCustomFrame, parent);
window->setWindowTitle("Chatterino - " + title); window->setWindowTitle("Chatterino - " + title);
window->setAttribute(Qt::WA_DeleteOnClose); window->setAttribute(Qt::WA_DeleteOnClose);
auto layout = new QVBoxLayout(); auto layout = new QVBoxLayout();