mirror-chatterino2/src/widgets/BaseWindow.hpp

100 lines
2.7 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;
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,
2018-06-11 15:04:54 +02:00
DeleteOnFocusOut = 8,
DisableCustomScaling = 16,
FramelessDraggable = 32,
2018-06-06 13:35:06 +02:00
};
2018-05-23 22:27:29 +02:00
2018-06-11 15:04:54 +02:00
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None);
QWidget *getLayoutContainer();
bool hasCustomWindowFrame();
void 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;
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();
protected:
#ifdef USEWINSDK
2018-06-06 13:35:06 +02:00
virtual void showEvent(QShowEvent *) override;
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
virtual void scaleChangedEvent(float) override;
#endif
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-06-06 13:35:06 +02:00
virtual void themeRefreshEvent() override;
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();
private:
void init();
void moveIntoDesktopRect(QWidget *parent);
void calcButtonsSizes();
2018-06-11 15:04:54 +02:00
bool enableCustomFrame_;
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_;
};
} // namespace chatterino