Add option to disallow resizing in FramelessDialog

This commit is contained in:
Ryan Huffman 2014-04-25 10:11:22 -07:00
parent 225c022511
commit dd844437b6
2 changed files with 5 additions and 1 deletions

View file

@ -16,6 +16,7 @@ const int RESIZE_HANDLE_WIDTH = 7;
FramelessDialog::FramelessDialog(QWidget *parent, Qt::WindowFlags flags, Position position) :
QDialog(parent, flags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint),
_allowResize(true),
_isResizing(false),
_resizeInitialWidth(0),
_selfHidden(false),
@ -107,7 +108,7 @@ void FramelessDialog::resizeAndPosition(bool resizeParent) {
}
void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) {
if (mouseEvent->button() == Qt::LeftButton) {
if (_allowResize && mouseEvent->button() == Qt::LeftButton) {
bool hitLeft = _position == POSITION_LEFT && abs(mouseEvent->pos().x() - size().width()) < RESIZE_HANDLE_WIDTH;
bool hitRight = _position == POSITION_RIGHT && mouseEvent->pos().x() < RESIZE_HANDLE_WIDTH;
if (hitLeft || hitRight) {

View file

@ -23,6 +23,8 @@ public:
FramelessDialog(QWidget* parent = 0, Qt::WindowFlags flags = 0, Position position = POSITION_LEFT);
void setStyleSheetFile(const QString& fileName);
void setAllowResize(bool allowResize) { _allowResize = allowResize; };
bool getAllowResize() { return _allowResize; };
protected:
virtual void mouseMoveEvent(QMouseEvent* mouseEvent);
@ -35,6 +37,7 @@ protected:
private:
void resizeAndPosition(bool resizeParent = true);
bool _allowResize;
bool _isResizing;
int _resizeInitialWidth;
bool _selfHidden; ///< true when the dialog itself because of a window event (deactivation or minimization)