Showing the changes to interface/src/ui/FramelessDialog.cpp (1 of 45 files). Show all
Unified · Split
| @@ -20,7 +20,8 @@ FramelessDialog::FramelessDialog(QWidget *parent, Qt::WindowFlags flags, Positio · 19 unmodified lines | ||
| 20 | 20 | _isResizing(false), |
| 21 | 21 | _resizeInitialWidth(0), |
| 22 | 22 | _selfHidden(false), |
| 23 | − _position(position) { | |
| 23 | + _position(position), | |
| 24 | + _hideOnBlur(true) { | |
| 24 | 25 | |
| 25 | 26 | setAttribute(Qt::WA_DeleteOnClose); |
| 26 | 27 | |
| @@ -44,7 +45,7 @@ bool FramelessDialog::eventFilter(QObject* sender, QEvent* event) { · 17 unmodified lines | ||
| 44 | 45 | } |
| 45 | 46 | break; |
| 46 | 47 | case QEvent::WindowStateChange: |
| 47 | − if (parentWidget()->isMinimized()) { | |
| 48 | + if (_hideOnBlur && parentWidget()->isMinimized()) { | |
| 48 | 49 | if (isVisible()) { |
| 49 | 50 | _selfHidden = true; |
| 50 | 51 | setHidden(true); |
| @@ -56,7 +57,7 @@ bool FramelessDialog::eventFilter(QObject* sender, QEvent* event) { · 5 unmodified lines | ||
| 56 | 57 | break; |
| 57 | 58 | case QEvent::ApplicationDeactivate: |
| 58 | 59 | // hide on minimize and focus lost |
| 59 | − if (isVisible()) { | |
| 60 | + if (_hideOnBlur && isVisible()) { | |
| 60 | 61 | _selfHidden = true; |
| 61 | 62 | setHidden(true); |
| 62 | 63 | } |
| @@ -85,18 +86,23 @@ void FramelessDialog::setStyleSheetFile(const QString& fileName) { · 22 unmodified lines | ||
| 85 | 86 | |
| 86 | 87 | void FramelessDialog::showEvent(QShowEvent* event) { |
| 87 | 88 | resizeAndPosition(); |
| 89 | + QDialog::showEvent(event); | |
| 88 | 90 | } |
| 89 | 91 | |
| 90 | 92 | void FramelessDialog::resizeAndPosition(bool resizeParent) { |
| 91 | − // keep full app height | |
| 92 | − setFixedHeight(parentWidget()->size().height()); | |
| 93 | + // keep full app height or width depending on position | |
| 94 | + if (_position == POSITION_LEFT || _position == POSITION_RIGHT) { | |
| 95 | + setFixedHeight(parentWidget()->size().height()); | |
| 96 | + } else { | |
| 97 | + setFixedWidth(parentWidget()->size().width()); | |
| 98 | + } | |
| 93 | 99 | |
| 94 | 100 | // resize parrent if width is smaller than this dialog |
| 95 | 101 | if (resizeParent && parentWidget()->size().width() < size().width()) { |
| 96 | 102 | parentWidget()->resize(size().width(), parentWidget()->size().height()); |
| 97 | 103 | } |
| 98 | 104 | |
| 99 | − if (_position == POSITION_LEFT) { | |
| 105 | + if (_position == POSITION_LEFT || _position == POSITION_TOP) { | |
| 100 | 106 | // move to upper left corner |
| 101 | 107 | move(parentWidget()->geometry().topLeft()); |
| 102 | 108 | } else if (_position == POSITION_RIGHT) { |
| @@ -105,16 +111,26 @@ void FramelessDialog::resizeAndPosition(bool resizeParent) { · 2 unmodified lines | ||
| 105 | 111 | pos.setX(pos.x() - size().width()); |
| 106 | 112 | move(pos); |
| 107 | 113 | } |
| 114 | + repaint(); | |
| 108 | 115 | } |
| 109 | 116 | |
| 110 | 117 | void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) { |
| 111 | 118 | if (_allowResize && mouseEvent->button() == Qt::LeftButton) { |
| 112 | − bool hitLeft = _position == POSITION_LEFT && abs(mouseEvent->pos().x() - size().width()) < RESIZE_HANDLE_WIDTH; | |
| 113 | − bool hitRight = _position == POSITION_RIGHT && mouseEvent->pos().x() < RESIZE_HANDLE_WIDTH; | |
| 114 | − if (hitLeft || hitRight) { | |
| 115 | − _isResizing = true; | |
| 116 | − _resizeInitialWidth = size().width(); | |
| 117 | − QApplication::setOverrideCursor(Qt::SizeHorCursor); | |
| 119 | + if (_position == POSITION_LEFT || _position == POSITION_RIGHT) { | |
| 120 | + bool hitLeft = (_position == POSITION_LEFT) && (abs(mouseEvent->pos().x() - size().width()) < RESIZE_HANDLE_WIDTH); | |
| 121 | + bool hitRight = (_position == POSITION_RIGHT) && (mouseEvent->pos().x() < RESIZE_HANDLE_WIDTH); | |
| 122 | + if (hitLeft || hitRight) { | |
| 123 | + _isResizing = true; | |
| 124 | + _resizeInitialWidth = size().width(); | |
| 125 | + QApplication::setOverrideCursor(Qt::SizeHorCursor); | |
| 126 | + } | |
| 127 | + } else { | |
| 128 | + bool hitTop = (_position == POSITION_TOP) && (abs(mouseEvent->pos().y() - size().height()) < RESIZE_HANDLE_WIDTH); | |
| 129 | + if (hitTop) { | |
| 130 | + _isResizing = true; | |
| 131 | + _resizeInitialWidth = size().height(); | |
| 132 | + QApplication::setOverrideCursor(Qt::SizeHorCursor); | |
| 133 | + } | |
| 118 | 134 | } |
| 119 | 135 | } |
| 120 | 136 | } |
| @@ -134,6 +150,8 @@ void FramelessDialog::mouseMoveEvent(QMouseEvent* mouseEvent) { · 13 unmodified lines | ||
| 134 | 150 | resizeAndPosition(); |
| 135 | 151 | _resizeInitialWidth = size().width(); |
| 136 | 152 | setUpdatesEnabled(true); |
| 153 | + } else if (_position == POSITION_TOP) { | |
| 154 | + resize(size().width(), mouseEvent->pos().y()); | |
| 137 | 155 | } |
| 138 | 156 | } |
| 139 | 157 | } |