History

Merge remote-tracking branch 'upstream/master' into RunningScripts

Ryan Huffman committed 12 years ago

Commit edcff0b2 parents f889cef a934ffb45 files · +1654 −425Browse files

Showing the changes to interface/src/ui/FramelessDialog.cpp (1 of 45 files). Show all

Unified · Split

interface/src/ui/FramelessDialog.cpp+30−12
@@ -20,7 +20,8 @@ FramelessDialog::FramelessDialog(QWidget *parent, Qt::WindowFlags flags, Positio · 19 unmodified lines
2020 _isResizing(false),
2121 _resizeInitialWidth(0),
2222 _selfHidden(false),
23− _position(position) {
23+ _position(position),
24+ _hideOnBlur(true) {
2425
2526 setAttribute(Qt::WA_DeleteOnClose);
2627
@@ -44,7 +45,7 @@ bool FramelessDialog::eventFilter(QObject* sender, QEvent* event) { · 17 unmodified lines
4445 }
4546 break;
4647 case QEvent::WindowStateChange:
47− if (parentWidget()->isMinimized()) {
48+ if (_hideOnBlur && parentWidget()->isMinimized()) {
4849 if (isVisible()) {
4950 _selfHidden = true;
5051 setHidden(true);
@@ -56,7 +57,7 @@ bool FramelessDialog::eventFilter(QObject* sender, QEvent* event) { · 5 unmodified lines
5657 break;
5758 case QEvent::ApplicationDeactivate:
5859 // hide on minimize and focus lost
59− if (isVisible()) {
60+ if (_hideOnBlur && isVisible()) {
6061 _selfHidden = true;
6162 setHidden(true);
6263 }
@@ -85,18 +86,23 @@ void FramelessDialog::setStyleSheetFile(const QString& fileName) { · 22 unmodified lines
8586
8687 void FramelessDialog::showEvent(QShowEvent* event) {
8788 resizeAndPosition();
89+ QDialog::showEvent(event);
8890 }
8991
9092 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+ }
9399
94100 // resize parrent if width is smaller than this dialog
95101 if (resizeParent && parentWidget()->size().width() < size().width()) {
96102 parentWidget()->resize(size().width(), parentWidget()->size().height());
97103 }
98104
99− if (_position == POSITION_LEFT) {
105+ if (_position == POSITION_LEFT || _position == POSITION_TOP) {
100106 // move to upper left corner
101107 move(parentWidget()->geometry().topLeft());
102108 } else if (_position == POSITION_RIGHT) {
@@ -105,16 +111,26 @@ void FramelessDialog::resizeAndPosition(bool resizeParent) { · 2 unmodified lines
105111 pos.setX(pos.x() - size().width());
106112 move(pos);
107113 }
114+ repaint();
108115 }
109116
110117 void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) {
111118 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+ }
118134 }
119135 }
120136 }
@@ -134,6 +150,8 @@ void FramelessDialog::mouseMoveEvent(QMouseEvent* mouseEvent) { · 13 unmodified lines
134150 resizeAndPosition();
135151 _resizeInitialWidth = size().width();
136152 setUpdatesEnabled(true);
153+ } else if (_position == POSITION_TOP) {
154+ resize(size().width(), mouseEvent->pos().y());
137155 }
138156 }
139157 }