tdesktop/Telegram/SourceFiles/ui/wrap/padding_wrap.h

111 lines
2.1 KiB
C
Raw Normal View History

2017-09-13 16:57:44 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2017-09-13 16:57:44 +00:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2017-09-13 16:57:44 +00:00
*/
#pragma once
#include "ui/wrap/wrap.h"
namespace Ui {
template <typename Widget = RpWidget>
class PaddingWrap;
template <>
class PaddingWrap<RpWidget> : public Wrap<RpWidget> {
using Parent = Wrap<RpWidget>;
public:
PaddingWrap(
QWidget *parent,
object_ptr<RpWidget> &&child,
2017-09-13 16:57:44 +00:00
const style::margins &padding);
style::margins padding() const {
return _padding;
}
void setPadding(const style::margins &padding);
2017-09-13 16:57:44 +00:00
int naturalWidth() const override;
protected:
int resizeGetHeight(int newWidth) override;
void wrappedSizeUpdated(QSize size) override;
private:
style::margins _padding;
};
template <typename Widget>
class PaddingWrap : public Wrap<Widget, PaddingWrap<RpWidget>> {
using Parent = Wrap<Widget, PaddingWrap<RpWidget>>;
public:
PaddingWrap(
QWidget *parent,
object_ptr<Widget> &&child,
2017-09-13 16:57:44 +00:00
const style::margins &padding)
: Parent(parent, std::move(child), padding) {
}
};
2018-04-16 17:02:40 +00:00
template <typename Widget = RpWidget>
class CenterWrap;
template <>
class CenterWrap<RpWidget> : public Wrap<RpWidget> {
using Parent = Wrap<RpWidget>;
public:
CenterWrap(
QWidget *parent,
object_ptr<RpWidget> &&child);
int naturalWidth() const override;
protected:
int resizeGetHeight(int newWidth) override;
void wrappedSizeUpdated(QSize size) override;
private:
void updateWrappedPosition(int forWidth);
};
template <typename Widget>
class CenterWrap : public Wrap<Widget, CenterWrap<RpWidget>> {
using Parent = Wrap<Widget, CenterWrap<RpWidget>>;
public:
CenterWrap(
QWidget *parent,
object_ptr<Widget> &&child)
: Parent(parent, std::move(child)) {
}
};
class FixedHeightWidget : public RpWidget {
public:
FixedHeightWidget(QWidget *parent, int height)
: RpWidget(parent) {
resize(width(), height);
2017-09-13 16:57:44 +00:00
}
};
inline object_ptr<FixedHeightWidget> CreateSkipWidget(
2017-09-21 10:28:34 +00:00
QWidget *parent,
int skip) {
return object_ptr<FixedHeightWidget>(
2017-09-21 10:28:34 +00:00
parent,
skip);
2017-09-21 10:28:34 +00:00
}
2017-09-13 16:57:44 +00:00
} // namespace Ui