mirror-chatterino2/src/widgets/BaseWindow.hpp

119 lines
3.4 KiB
C++
Raw Normal View History

#pragma once
2018-06-26 14:09:39 +02:00
#include "BaseWidget.hpp"
#include "widgets/helper/TitlebarButton.hpp"
2018-01-24 15:08:22 +01:00
#include <functional>
2018-06-11 15:04:54 +02:00
#include <pajlada/signals/signalholder.hpp>
2018-01-24 15:08:22 +01:00
class QHBoxLayout;
struct tagMSG;
typedef struct tagMSG MSG;
namespace chatterino {
class RippleEffectButton;
2018-02-05 23:32:38 +01:00
class RippleEffectLabel;
class TitleBarButton;
class BaseWindow : public BaseWidget
{
Q_OBJECT
public:
2018-06-06 13:35:06 +02:00
enum Flags {
None = 0,
EnableCustomFrame = 1,
Frameless = 2,
TopMost = 4,
DisableCustomScaling = 8,
FramelessDraggable = 16,
2018-06-06 13:35:06 +02:00
};
2018-05-23 22:27:29 +02:00
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
2018-06-11 15:04:54 +02:00
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None);
QWidget *getLayoutContainer();
bool hasCustomWindowFrame();
TitleBarButton *addTitleBarButton(const TitleBarButton::Style &style,
std::function<void()> onClicked);
2018-02-05 23:32:38 +01:00
RippleEffectLabel *addTitleBarLabel(std::function<void()> onClicked);
void setStayInScreenRect(bool value);
bool getStayInScreenRect() const;
void setActionOnFocusLoss(ActionOnFocusLoss value);
ActionOnFocusLoss getActionOnFocusLoss() const;
2018-05-26 17:11:09 +02:00
void moveTo(QWidget *widget, QPoint point, bool offset = true);
2018-06-24 13:32:56 +02:00
virtual float getScale() const override;
Flags getFlags();
2018-07-05 11:42:40 +02:00
pajlada::Signals::NoArgSignal closing;
protected:
2018-06-06 13:35:06 +02:00
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
virtual void scaleChangedEvent(float) override;
2018-06-06 13:35:06 +02:00
virtual void paintEvent(QPaintEvent *) override;
2018-06-06 10:46:23 +02:00
2018-06-06 13:35:06 +02:00
virtual void changeEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;
2018-07-05 11:42:40 +02:00
virtual void closeEvent(QCloseEvent *) override;
2018-07-06 17:11:37 +02:00
virtual void themeChangedEvent() override;
2018-06-06 13:35:06 +02:00
virtual bool event(QEvent *event) override;
2018-06-11 15:04:54 +02:00
virtual void wheelEvent(QWheelEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
QPointF movingRelativePos;
bool moving{};
2018-06-11 15:04:54 +02:00
void updateScale();
boost::optional<QColor> overrideBackgroundColor_;
private:
void init();
void moveIntoDesktopRect(QWidget *parent);
void calcButtonsSizes();
void drawCustomWindowFrame(QPainter &painter);
void onFocusLost();
bool handleDPICHANGED(MSG *msg);
bool handleSHOWWINDOW(MSG *msg);
bool handleNCCALCSIZE(MSG *msg, long *result);
bool handleSIZE(MSG *msg);
bool handleNCHITTEST(MSG *msg, long *result);
2018-06-11 15:04:54 +02:00
bool enableCustomFrame_;
ActionOnFocusLoss actionOnFocusLoss_ = Nothing;
2018-06-11 15:04:54 +02:00
bool frameless_;
bool stayInScreenRect_ = false;
bool shown_ = false;
Flags flags_;
float nativeScale_ = 1;
struct {
2018-06-24 21:57:03 +02:00
QLayout *windowLayout = nullptr;
2018-05-23 22:27:29 +02:00
QHBoxLayout *titlebarBox = nullptr;
QWidget *titleLabel = nullptr;
TitleBarButton *minButton = nullptr;
TitleBarButton *maxButton = nullptr;
TitleBarButton *exitButton = nullptr;
2018-05-23 22:27:29 +02:00
QWidget *layoutBase = nullptr;
std::vector<RippleEffectButton *> buttons;
2018-06-11 15:04:54 +02:00
} ui_;
pajlada::Signals::SignalHolder connections_;
2018-06-25 22:27:51 +02:00
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
};
} // namespace chatterino