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/aboutpage.cpp \
src/widgets/settingspages/moderationpage.cpp \
src/widgets/settingspages/logspage.cpp
src/widgets/settingspages/logspage.cpp \
src/widgets/basewindow.cpp
HEADERS += \
src/precompiled_headers.hpp \
@ -224,7 +225,8 @@ HEADERS += \
src/widgets/settingspages/accountspage.hpp \
src/widgets/settingspages/aboutpage.hpp \
src/widgets/settingspages/moderationpage.hpp \
src/widgets/settingspages/logspage.hpp
src/widgets/settingspages/logspage.hpp \
src/widgets/basewindow.hpp
PRECOMPILED_HEADER =

View file

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

View file

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

View file

@ -1,14 +1,12 @@
#include "widgets/basewidget.hpp"
#include "singletons/settingsmanager.hpp"
#include "singletons/thememanager.hpp"
#include "widgets/tooltipwidget.hpp"
#include <QDebug>
#include <QIcon>
#include <QLayout>
#include <QtGlobal>
#include <boost/signals2.hpp>
#include "util/nativeeventhelper.hpp"
namespace chatterino {
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()
{
// 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 chatterino

View file

@ -15,9 +15,7 @@ class BaseWidget : public QWidget
public:
explicit BaseWidget(singletons::ThemeManager &_themeManager, QWidget *parent);
explicit BaseWidget(BaseWidget *parent);
explicit BaseWidget(QWidget *parent = nullptr);
singletons::ThemeManager &themeManager;
@ -25,22 +23,13 @@ public:
float getDpiMultiplier();
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*/)
{
}
void initAsWindow();
private:
bool isWindow = false;
float dpiMultiplier = 1.f;
private:
void init();
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 {
EmotePopup::EmotePopup(singletons::ThemeManager &themeManager)
: BaseWidget(themeManager, 0)
: BaseWindow(themeManager, 0)
{
this->initAsWindow();
this->viewEmotes = new ChannelView();
this->viewEmojis = new ChannelView();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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