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