moved window logic from BaseWidget to BaseWindow

This commit is contained in:
fourtf 2018-01-14 21:55:36 +01:00
parent 8deb096a27
commit e19a83679f
17 changed files with 138 additions and 104 deletions

View file

@ -126,7 +126,8 @@ SOURCES += \
src/widgets/settingspages/accountspage.cpp \ src/widgets/settingspages/accountspage.cpp \
src/widgets/settingspages/aboutpage.cpp \ src/widgets/settingspages/aboutpage.cpp \
src/widgets/settingspages/moderationpage.cpp \ src/widgets/settingspages/moderationpage.cpp \
src/widgets/settingspages/logspage.cpp src/widgets/settingspages/logspage.cpp \
src/widgets/basewindow.cpp
HEADERS += \ HEADERS += \
src/precompiled_headers.hpp \ src/precompiled_headers.hpp \
@ -224,7 +225,8 @@ HEADERS += \
src/widgets/settingspages/accountspage.hpp \ src/widgets/settingspages/accountspage.hpp \
src/widgets/settingspages/aboutpage.hpp \ src/widgets/settingspages/aboutpage.hpp \
src/widgets/settingspages/moderationpage.hpp \ src/widgets/settingspages/moderationpage.hpp \
src/widgets/settingspages/logspage.hpp src/widgets/settingspages/logspage.hpp \
src/widgets/basewindow.hpp
PRECOMPILED_HEADER = PRECOMPILED_HEADER =

View file

@ -19,7 +19,7 @@ namespace chatterino {
namespace widgets { namespace widgets {
AccountPopupWidget::AccountPopupWidget(SharedChannel _channel) AccountPopupWidget::AccountPopupWidget(SharedChannel _channel)
: BaseWidget() : BaseWindow()
, ui(new Ui::AccountPopup) , ui(new Ui::AccountPopup)
, channel(_channel) , channel(_channel)
{ {
@ -28,7 +28,6 @@ AccountPopupWidget::AccountPopupWidget(SharedChannel _channel)
this->layout()->setSizeConstraint(QLayout::SetFixedSize); this->layout()->setSizeConstraint(QLayout::SetFixedSize);
this->setWindowFlags(Qt::FramelessWindowHint); this->setWindowFlags(Qt::FramelessWindowHint);
this->initAsWindow();
this->resize(0, 0); this->resize(0, 0);

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "basewidget.hpp" #include "basewindow.hpp"
#include "twitch/twitchchannel.hpp" #include "twitch/twitchchannel.hpp"
#include "util/concurrentmap.hpp" #include "util/concurrentmap.hpp"
@ -19,7 +19,7 @@ class Channel;
namespace widgets { namespace widgets {
class AccountPopupWidget : public BaseWidget class AccountPopupWidget : public BaseWindow
{ {
Q_OBJECT Q_OBJECT
public: public:

View file

@ -1,14 +1,12 @@
#include "widgets/basewidget.hpp" #include "widgets/basewidget.hpp"
#include "singletons/settingsmanager.hpp" #include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp" #include "singletons/thememanager.hpp"
#include "widgets/tooltipwidget.hpp"
#include <QDebug> #include <QDebug>
#include <QIcon> #include <QIcon>
#include <QLayout> #include <QLayout>
#include <QtGlobal> #include <QtGlobal>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
#include "util/nativeeventhelper.hpp"
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
@ -61,64 +59,10 @@ void BaseWidget::init()
}); });
} }
void BaseWidget::initAsWindow()
{
this->setWindowIcon(QIcon(":/images/icon.png"));
this->isWindow = true;
#ifdef USEWINSDK
auto dpi = util::getWindowDpi(this->winId());
if (dpi) {
this->dpiMultiplier = dpi.value() / 96.f;
}
#endif
if (singletons::SettingManager::getInstance().windowTopMost.getValue()) {
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
}
}
void BaseWidget::refreshTheme() void BaseWidget::refreshTheme()
{ {
// Do any color scheme updates here // Do any color scheme updates here
} }
#ifdef USEWINSDK
bool BaseWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
int dpi;
if (util::tryHandleDpiChangedMessage(message, dpi)) {
qDebug() << "dpi changed";
float oldDpiMultiplier = this->dpiMultiplier;
this->dpiMultiplier = dpi / 96.f;
float scale = this->dpiMultiplier / oldDpiMultiplier;
this->dpiMultiplierChanged(oldDpiMultiplier, this->dpiMultiplier);
this->resize(static_cast<int>(this->width() * scale),
static_cast<int>(this->height() * scale));
}
return QWidget::nativeEvent(eventType, message, result);
}
#endif
void BaseWidget::changeEvent(QEvent *)
{
if (this->isWindow) {
TooltipWidget::getInstance()->hide();
}
}
void BaseWidget::leaveEvent(QEvent *)
{
if (this->isWindow) {
TooltipWidget::getInstance()->hide();
}
}
} // namespace widgets } // namespace widgets
} // namespace chatterino } // namespace chatterino

View file

@ -15,9 +15,7 @@ class BaseWidget : public QWidget
public: public:
explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent); explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent);
explicit BaseWidget(BaseWidget *parent); explicit BaseWidget(BaseWidget *parent);
explicit BaseWidget(QWidget *parent = nullptr); explicit BaseWidget(QWidget *parent = nullptr);
singletons::ThemeManager &themeManager; singletons::ThemeManager &themeManager;
@ -25,22 +23,13 @@ public:
float getDpiMultiplier(); float getDpiMultiplier();
protected: protected:
#ifdef USEWINSDK
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
#endif
virtual void changeEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void dpiMultiplierChanged(float /*oldDpi*/, float /*newDpi*/) virtual void dpiMultiplierChanged(float /*oldDpi*/, float /*newDpi*/)
{ {
} }
void initAsWindow();
private:
bool isWindow = false;
float dpiMultiplier = 1.f; float dpiMultiplier = 1.f;
private:
void init(); void init();
virtual void refreshTheme(); virtual void refreshTheme();

View file

@ -0,0 +1,83 @@
#include "basewindow.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/nativeeventhelper.hpp"
#include "widgets/tooltipwidget.hpp"
#include <QDebug>
#include <QIcon>
namespace chatterino {
namespace widgets {
BaseWindow::BaseWindow(singletons::ThemeManager &_themeManager, QWidget *parent)
: BaseWidget(_themeManager, parent)
{
this->init();
}
BaseWindow::BaseWindow(BaseWidget *parent)
: BaseWidget(parent)
{
this->init();
}
BaseWindow::BaseWindow(QWidget *parent)
: BaseWidget(parent)
{
this->init();
}
void BaseWindow::init()
{
this->setWindowIcon(QIcon(":/images/icon.png"));
#ifdef USEWINSDK
auto dpi = util::getWindowDpi(this->winId());
if (dpi) {
this->dpiMultiplier = dpi.value() / 96.f;
}
this->dpiMultiplierChanged(1, this->dpiMultiplier);
#endif
if (singletons::SettingManager::getInstance().windowTopMost.getValue()) {
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
}
}
void BaseWindow::changeEvent(QEvent *)
{
TooltipWidget::getInstance()->hide();
}
void BaseWindow::leaveEvent(QEvent *)
{
TooltipWidget::getInstance()->hide();
}
#ifdef USEWINSDK
bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
int dpi;
if (util::tryHandleDpiChangedMessage(message, dpi)) {
qDebug() << "dpi changed";
float oldDpiMultiplier = this->dpiMultiplier;
this->dpiMultiplier = dpi / 96.f;
float scale = this->dpiMultiplier / oldDpiMultiplier;
this->dpiMultiplierChanged(oldDpiMultiplier, this->dpiMultiplier);
this->resize(static_cast<int>(this->width() * scale),
static_cast<int>(this->height() * scale));
}
return QWidget::nativeEvent(eventType, message, result);
}
#endif
} // namespace widgets
} // namespace chatterino

View file

@ -0,0 +1,27 @@
#pragma once
#include "basewidget.hpp"
namespace chatterino {
namespace widgets {
class BaseWindow : public BaseWidget
{
public:
explicit BaseWindow(singletons::ThemeManager &_themeManager, QWidget *parent);
explicit BaseWindow(BaseWidget *parent);
explicit BaseWindow(QWidget *parent = nullptr);
protected:
#ifdef USEWINSDK
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
#endif
virtual void changeEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
private:
void init();
};
} // namespace widgets
} // namespace chatterino

View file

@ -13,10 +13,8 @@ namespace chatterino {
namespace widgets { namespace widgets {
EmotePopup::EmotePopup(singletons::ThemeManager &themeManager) EmotePopup::EmotePopup(singletons::ThemeManager &themeManager)
: BaseWidget(themeManager, 0) : BaseWindow(themeManager, 0)
{ {
this->initAsWindow();
this->viewEmotes = new ChannelView(); this->viewEmotes = new ChannelView();
this->viewEmojis = new ChannelView(); this->viewEmojis = new ChannelView();

View file

@ -1,13 +1,13 @@
#pragma once #pragma once
#include "channel.hpp" #include "channel.hpp"
#include "widgets/basewidget.hpp" #include "widgets/basewindow.hpp"
#include "widgets/helper/channelview.hpp" #include "widgets/helper/channelview.hpp"
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
class EmotePopup : public BaseWidget class EmotePopup : public BaseWindow
{ {
public: public:
explicit EmotePopup(singletons::ThemeManager &); explicit EmotePopup(singletons::ThemeManager &);

View file

@ -11,7 +11,6 @@ namespace chatterino {
namespace widgets { namespace widgets {
SearchPopup::SearchPopup() SearchPopup::SearchPopup()
{ {
this->initAsWindow();
this->initLayout(); this->initLayout();
this->resize(400, 600); this->resize(400, 600);
} }
@ -76,14 +75,13 @@ void SearchPopup::performSearch()
for (size_t i = 0; i < this->snapshot.getLength(); i++) { for (size_t i = 0; i < this->snapshot.getLength(); i++) {
messages::MessagePtr message = this->snapshot[i]; messages::MessagePtr message = this->snapshot[i];
if (text.isEmpty() || if (text.isEmpty() || message->getSearchText().indexOf(this->searchInput->text(), 0,
message->getSearchText().indexOf(this->searchInput->text(), 0, Qt::CaseInsensitive) != Qt::CaseInsensitive) != -1) {
-1) {
channel->addMessage(message); channel->addMessage(message);
} }
} }
this->channelView->setChannel(channel); this->channelView->setChannel(channel);
} }
} } // namespace widgets
} } // namespace chatterino

View file

@ -4,7 +4,7 @@
#include "messages/limitedqueuesnapshot.hpp" #include "messages/limitedqueuesnapshot.hpp"
#include "messages/message.hpp" #include "messages/message.hpp"
#include "widgets/basewidget.hpp" #include "widgets/basewindow.hpp"
class QLineEdit; class QLineEdit;
namespace chatterino { namespace chatterino {
@ -12,7 +12,7 @@ class Channel;
namespace widgets { namespace widgets {
class ChannelView; class ChannelView;
class SearchPopup : public BaseWidget class SearchPopup : public BaseWindow
{ {
public: public:
SearchPopup(); SearchPopup();
@ -27,5 +27,5 @@ private:
void initLayout(); void initLayout();
void performSearch(); void performSearch();
}; };
} } // namespace widgets
} } // namespace chatterino

View file

@ -6,12 +6,10 @@ namespace chatterino {
namespace widgets { namespace widgets {
QualityPopup::QualityPopup(const QString &channel, const QString &path, QStringList options) QualityPopup::QualityPopup(const QString &channel, const QString &path, QStringList options)
: BaseWidget() : BaseWindow()
, channel(channel) , channel(channel)
, path(path) , path(path)
{ {
this->initAsWindow();
this->ui.okButton.setText("OK"); this->ui.okButton.setText("OK");
this->ui.cancelButton.setText("Cancel"); this->ui.cancelButton.setText("Cancel");

View file

@ -8,13 +8,13 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget> #include <QWidget>
#include "basewidget.hpp" #include "basewindow.hpp"
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
class QualityPopup : public BaseWidget class QualityPopup : public BaseWindow
{ {
public: public:
QualityPopup(const QString &channel, const QString &path, QStringList options); QualityPopup(const QString &channel, const QString &path, QStringList options);

View file

@ -19,10 +19,8 @@ namespace widgets {
SettingsDialog *SettingsDialog::handle = nullptr; SettingsDialog *SettingsDialog::handle = nullptr;
SettingsDialog::SettingsDialog() SettingsDialog::SettingsDialog()
: BaseWidget() : BaseWindow()
{ {
this->initAsWindow();
this->initUi(); this->initUi();
this->addTabs(); this->addTabs();

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "basewidget.hpp" #include "basewindow.hpp"
#include <QPushButton> #include <QPushButton>
#include <QStackedLayout> #include <QStackedLayout>
@ -17,7 +17,7 @@ class SettingsPage;
class SettingsDialogTab; class SettingsDialogTab;
class SettingsDialog : public BaseWidget class SettingsDialog : public BaseWindow
{ {
public: public:
SettingsDialog(); SettingsDialog();

View file

@ -18,15 +18,13 @@ namespace widgets {
Window::Window(const QString &windowName, singletons::ThemeManager &_themeManager, Window::Window(const QString &windowName, singletons::ThemeManager &_themeManager,
bool _isMainWindow) bool _isMainWindow)
: BaseWidget(_themeManager, nullptr) : BaseWindow(_themeManager, nullptr)
, settingRoot(fS("/windows/{}", windowName)) , settingRoot(fS("/windows/{}", windowName))
, windowGeometry(this->settingRoot) , windowGeometry(this->settingRoot)
, dpi(this->getDpiMultiplier()) , dpi(this->getDpiMultiplier())
, themeManager(_themeManager) , themeManager(_themeManager)
, notebook(this, _isMainWindow, this->settingRoot) , notebook(this, _isMainWindow, this->settingRoot)
{ {
this->initAsWindow();
singletons::AccountManager::getInstance().Twitch.currentUsername.connect( singletons::AccountManager::getInstance().Twitch.currentUsername.connect(
[this](const std::string &newUsername, auto) { [this](const std::string &newUsername, auto) {
if (newUsername.empty()) { if (newUsername.empty()) {

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "util/helpers.hpp" #include "util/helpers.hpp"
#include "widgets/basewidget.hpp" #include "widgets/basewindow.hpp"
#include "widgets/notebook.hpp" #include "widgets/notebook.hpp"
#include "widgets/titlebar.hpp" #include "widgets/titlebar.hpp"
@ -35,7 +35,7 @@ struct WindowGeometry {
pajlada::Settings::Setting<int> height; pajlada::Settings::Setting<int> height;
}; };
class Window : public BaseWidget class Window : public BaseWindow
{ {
Q_OBJECT Q_OBJECT