mirror-chatterino2/src/widgets/BaseWindow.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

167 lines
4.4 KiB
C++
Raw Normal View History

#pragma once
#include "common/FlagsEnum.hpp"
#include "widgets/BaseWidget.hpp"
#include <pajlada/signals/signalholder.hpp>
#include <QTimer>
#include <functional>
class QHBoxLayout;
struct tagMSG;
typedef struct tagMSG MSG;
2019-10-07 15:46:08 +02:00
namespace chatterino {
class Button;
class EffectLabel;
class TitleBarButton;
enum class TitleBarButtonStyle;
class BaseWindow : public BaseWidget
{
Q_OBJECT
public:
enum Flags {
None = 0,
EnableCustomFrame = 1,
Frameless = 2,
TopMost = 4,
DisableCustomScaling = 8,
FramelessDraggable = 16,
DontFocus = 32,
Dialog = 64,
DisableLayoutSave = 128,
};
enum class BoundsChecker {
// Don't attempt to do any "stay in screen" stuff, just move me!
Off,
// Attempt to keep the window within bounds of the screen the cursor is on
CursorPosition,
// Attempt to keep the window within bounds of the screen the desired position is on
DesiredPosition,
};
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
2019-09-08 22:58:17 +02:00
explicit BaseWindow(FlagsEnum<Flags> flags_ = None,
QWidget *parent = nullptr);
2020-08-22 22:53:31 +02:00
~BaseWindow() override;
2019-09-01 14:06:30 +02:00
void setInitialBounds(const QRect &bounds);
QRect getBounds();
QWidget *getLayoutContainer();
bool hasCustomWindowFrame();
TitleBarButton *addTitleBarButton(const TitleBarButtonStyle &style,
std::function<void()> onClicked);
EffectLabel *addTitleBarLabel(std::function<void()> onClicked);
void setActionOnFocusLoss(ActionOnFocusLoss value);
ActionOnFocusLoss getActionOnFocusLoss() const;
void moveTo(QPoint point, BoundsChecker boundsChecker);
float scale() const override;
float qtFontScale() const;
pajlada::Signals::NoArgSignal closing;
2019-08-26 13:18:23 +02:00
static bool supportsCustomWindowFrame();
protected:
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool nativeEvent(const QByteArray &eventType, void *message,
qintptr *result) override;
#else
bool nativeEvent(const QByteArray &eventType, void *message,
long *result) override;
#endif
virtual void scaleChangedEvent(float) override;
virtual void paintEvent(QPaintEvent *) override;
virtual void changeEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;
virtual void moveEvent(QMoveEvent *) override;
virtual void closeEvent(QCloseEvent *) override;
2019-09-08 22:58:17 +02:00
virtual void showEvent(QShowEvent *) override;
virtual void themeChangedEvent() override;
virtual bool event(QEvent *event) override;
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{};
void updateScale();
boost::optional<QColor> overrideBackgroundColor_;
private:
void init();
/**
*
**/
void moveWithinScreen(QPoint point, QPoint origin);
void calcButtonsSizes();
void drawCustomWindowFrame(QPainter &painter);
void onFocusLost();
bool handleDPICHANGED(MSG *msg);
bool handleSHOWWINDOW(MSG *msg);
bool handleSIZE(MSG *msg);
2019-09-01 14:06:30 +02:00
bool handleMOVE(MSG *msg);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool handleNCCALCSIZE(MSG *msg, qintptr *result);
bool handleNCHITTEST(MSG *msg, qintptr *result);
#else
bool handleNCCALCSIZE(MSG *msg, long *result);
bool handleNCHITTEST(MSG *msg, long *result);
#endif
bool enableCustomFrame_;
ActionOnFocusLoss actionOnFocusLoss_ = Nothing;
bool frameless_;
bool shown_ = false;
2019-09-08 22:58:17 +02:00
FlagsEnum<Flags> flags_;
float nativeScale_ = 1;
2019-12-26 23:41:31 +01:00
bool isResizeFixing_ = false;
struct {
QLayout *windowLayout = nullptr;
QHBoxLayout *titlebarBox = nullptr;
QWidget *titleLabel = nullptr;
TitleBarButton *minButton = nullptr;
TitleBarButton *maxButton = nullptr;
TitleBarButton *exitButton = nullptr;
QWidget *layoutBase = nullptr;
std::vector<Button *> buttons;
} ui_;
2019-09-01 14:06:30 +02:00
#ifdef USEWINSDK
QRect initalBounds_;
QRect currentBounds_;
QRect nextBounds_;
QTimer useNextBounds_;
2019-09-01 14:06:30 +02:00
bool isNotMinimizedOrMaximized_{};
#endif
pajlada::Signals::SignalHolder connections_;
friend class BaseWidget;
};
2019-10-07 15:46:08 +02:00
} // namespace chatterino