2018-01-14 21:55:36 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "BaseWidget.hpp"
|
|
|
|
#include "widgets/helper/TitlebarButton.hpp"
|
2018-01-14 21:55:36 +01:00
|
|
|
|
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
|
|
|
|
2018-01-15 01:35:35 +01:00
|
|
|
class QHBoxLayout;
|
2018-07-03 13:04:27 +02:00
|
|
|
struct tagMSG;
|
|
|
|
typedef struct tagMSG MSG;
|
2018-01-15 01:35:35 +01:00
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
namespace chatterino {
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-01-24 20:27:56 +01:00
|
|
|
class RippleEffectButton;
|
2018-02-05 23:32:38 +01:00
|
|
|
class RippleEffectLabel;
|
2018-01-24 20:27:56 +01:00
|
|
|
class TitleBarButton;
|
2018-01-14 21:55:36 +01:00
|
|
|
|
|
|
|
class BaseWindow : public BaseWidget
|
|
|
|
{
|
2018-04-03 02:55:32 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
public:
|
2018-06-06 13:35:06 +02:00
|
|
|
enum Flags {
|
|
|
|
None = 0,
|
|
|
|
EnableCustomFrame = 1,
|
|
|
|
Frameless = 2,
|
|
|
|
TopMost = 4,
|
2018-07-05 10:34:04 +02:00
|
|
|
DisableCustomScaling = 8,
|
|
|
|
FramelessDraggable = 16,
|
2018-06-06 13:35:06 +02:00
|
|
|
};
|
2018-05-23 22:27:29 +02:00
|
|
|
|
2018-07-05 10:34:04 +02:00
|
|
|
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
|
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None);
|
2018-01-15 01:35:35 +01:00
|
|
|
|
|
|
|
QWidget *getLayoutContainer();
|
|
|
|
bool hasCustomWindowFrame();
|
2018-07-04 20:42:51 +02:00
|
|
|
TitleBarButton *addTitleBarButton(const TitleBarButton::Style &style,
|
|
|
|
std::function<void()> onClicked);
|
2018-02-05 23:32:38 +01:00
|
|
|
RippleEffectLabel *addTitleBarLabel(std::function<void()> onClicked);
|
2018-01-14 21:55:36 +01:00
|
|
|
|
2018-01-22 20:52:32 +01:00
|
|
|
void setStayInScreenRect(bool value);
|
|
|
|
bool getStayInScreenRect() const;
|
|
|
|
|
2018-07-05 10:34:04 +02:00
|
|
|
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-01-22 20:52:32 +01:00
|
|
|
|
2018-06-24 13:32:56 +02:00
|
|
|
virtual float getScale() const override;
|
|
|
|
|
2018-05-24 10:03:07 +02:00
|
|
|
Flags getFlags();
|
|
|
|
|
2018-07-05 11:42:40 +02:00
|
|
|
pajlada::Signals::NoArgSignal closing;
|
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
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-01-14 21:55:36 +01:00
|
|
|
|
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-01-14 21:55:36 +01:00
|
|
|
|
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;
|
|
|
|
|
2018-06-24 18:09:11 +02:00
|
|
|
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();
|
2018-01-15 01:35:35 +01:00
|
|
|
|
2018-07-03 16:55:02 +02:00
|
|
|
boost::optional<QColor> overrideBackgroundColor_;
|
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
private:
|
|
|
|
void init();
|
2018-01-22 20:52:32 +01:00
|
|
|
void moveIntoDesktopRect(QWidget *parent);
|
2018-04-18 18:10:47 +02:00
|
|
|
void calcButtonsSizes();
|
2018-07-03 13:04:27 +02:00
|
|
|
void drawCustomWindowFrame(QPainter &painter);
|
2018-07-05 10:34:04 +02:00
|
|
|
void onFocusLost();
|
2018-07-03 13:04:27 +02:00
|
|
|
|
|
|
|
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-01-15 01:35:35 +01:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
bool enableCustomFrame_;
|
2018-07-05 10:34:04 +02:00
|
|
|
ActionOnFocusLoss actionOnFocusLoss_ = Nothing;
|
2018-06-11 15:04:54 +02:00
|
|
|
bool frameless_;
|
|
|
|
bool stayInScreenRect_ = false;
|
|
|
|
bool shown_ = false;
|
|
|
|
Flags flags_;
|
|
|
|
float nativeScale_ = 1;
|
2018-01-15 01:35:35 +01:00
|
|
|
|
2018-04-18 18:10:47 +02:00
|
|
|
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;
|
2018-04-18 18:10:47 +02:00
|
|
|
TitleBarButton *minButton = nullptr;
|
|
|
|
TitleBarButton *maxButton = nullptr;
|
|
|
|
TitleBarButton *exitButton = nullptr;
|
2018-05-23 22:27:29 +02:00
|
|
|
QWidget *layoutBase = nullptr;
|
2018-04-18 18:10:47 +02:00
|
|
|
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;
|
2018-01-14 21:55:36 +01:00
|
|
|
};
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
} // namespace chatterino
|