mirror-chatterino2/src/widgets/basewindow.hpp

84 lines
2.1 KiB
C++
Raw Normal View History

#pragma once
#include "basewidget.hpp"
#include "widgets/helper/titlebarbutton.hpp"
2018-01-24 15:08:22 +01:00
#include <functional>
class QHBoxLayout;
namespace chatterino {
namespace widgets {
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,
DeleteOnFocusOut = 8
};
2018-05-23 22:27:29 +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);
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;
private:
void init();
void moveIntoDesktopRect(QWidget *parent);
void calcButtonsSizes();
bool enableCustomFrame;
2018-05-23 22:27:29 +02:00
bool frameless;
bool stayInScreenRect = false;
2018-01-24 15:08:22 +01:00
bool shown = false;
Flags flags;
struct {
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;
} ui;
};
} // namespace widgets
} // namespace chatterino