allow controlling the resize a bit more

this allows e.g. popupapplet to put constraints on where the edges of the window can resize to
and react differently when the user is actively resizing the dialog.

CCBUG:227095
This commit is contained in:
Aaron Seigo 2011-12-16 14:57:20 +01:00
parent 64373cf1da
commit d6e06ff92d
3 changed files with 87 additions and 3 deletions

View File

@ -490,8 +490,27 @@ void Dialog::mouseMoveEvent(QMouseEvent *event)
break; break;
} }
if ((newWidth >= minimumSize().width()) && (newHeight >= minimumSize().height())) { QRect newGeom(position, QSize(newWidth, newHeight));
setGeometry(QRect(position, QSize(newWidth, newHeight)));
// now sanity check the resize results again min constraints, if any
if (d->leftResizeMin > -1 && newGeom.left() > d->leftResizeMin) {
newGeom.setLeft(d->leftResizeMin);
}
if (d->topResizeMin > -1 && newGeom.top() > d->topResizeMin) {
newGeom.setTop(d->topResizeMin);
}
if (d->rightResizeMin > -1 && newGeom.right() < d->rightResizeMin) {
newGeom.setRight(d->rightResizeMin);
}
if (d->bottomResizeMin > -1 && newGeom.bottom() < d->bottomResizeMin) {
newGeom.setBottom(d->bottomResizeMin);
}
if ((newGeom.width() >= minimumSize().width()) && (newGeom.height() >= minimumSize().height())) {
setGeometry(newGeom);
} }
} }
@ -518,9 +537,9 @@ void Dialog::mousePressEvent(QMouseEvent *event)
void Dialog::mouseReleaseEvent(QMouseEvent *event) void Dialog::mouseReleaseEvent(QMouseEvent *event)
{ {
if (d->resizeStartCorner != Dialog::NoCorner) { if (d->resizeStartCorner != Dialog::NoCorner) {
emit dialogResized();
d->resizeStartCorner = Dialog::NoCorner; d->resizeStartCorner = Dialog::NoCorner;
unsetCursor(); unsetCursor();
emit dialogResized();
} }
QWidget::mouseReleaseEvent(event); QWidget::mouseReleaseEvent(event);
@ -745,6 +764,38 @@ Dialog::ResizeCorners Dialog::resizeCorners() const
return d->resizeCorners; return d->resizeCorners;
} }
bool Dialog::isUserResizing() const
{
return d->resizeStartCorner > NoCorner;
}
void Dialog::setMinimumResizeLimits(int left, int top, int right, int bottom)
{
d->leftResizeMin = left;
d->topResizeMin = top;
d->rightResizeMin = right;
d->bottomResizeMin = bottom;
}
void Dialog::getMinimumResizeLimits(int *left, int *top, int *right, int *bottom)
{
if (left) {
*left = d->leftResizeMin;
}
if (top) {
*top = d->topResizeMin;
}
if (right) {
*right = d->rightResizeMin;
}
if (bottom) {
*bottom = d->bottomResizeMin;
}
}
void Dialog::animatedHide(Plasma::Direction direction) void Dialog::animatedHide(Plasma::Direction direction)
{ {
if (!isVisible()) { if (!isVisible()) {

View File

@ -97,6 +97,31 @@ class PLASMA_EXPORT Dialog : public QWidget
*/ */
ResizeCorners resizeCorners() const; ResizeCorners resizeCorners() const;
/**
* @return true if currently being resized by the user
*/
bool isUserResizing() const;
/**
* Sets the minimum values that each of four sides of the rect may expand to or from
*
* @param left the screen coordinate that the left may not go beyond; -1 for no limit
* @param top the screen coordinate that the top may not go beyond; -1 for no limit
* @param right the screen coordinate that the right may not go beyond; -1 for no limit
* @param bottom the screen coordinate that the bottom may not go beyond; -1 for no limit
*/
void setMinimumResizeLimits(int left, int top, int right, int bottom);
/**
* Retrives the minimum resize limits for the dialog
*
* @param left the screen coordinate that the left may not go beyond; -1 for no limit
* @param top the screen coordinate that the top may not go beyond; -1 for no limit
* @param right the screen coordinate that the right may not go beyond; -1 for no limit
* @param bottom the screen coordinate that the bottom may not go beyond; -1 for no limit
*/
void getMinimumResizeLimits(int *left, int *top, int *right, int *bottom);
/** /**
* Causes an animated hide; requires compositing to work, otherwise * Causes an animated hide; requires compositing to work, otherwise
* the dialog will simply hide. * the dialog will simply hide.

View File

@ -40,6 +40,10 @@ public:
view(0), view(0),
resizeCorners(Dialog::NoCorner), resizeCorners(Dialog::NoCorner),
resizeStartCorner(Dialog::NoCorner), resizeStartCorner(Dialog::NoCorner),
leftResizeMin(-1),
topResizeMin(-1),
rightResizeMin(-1),
bottomResizeMin(-1),
moveTimer(0), moveTimer(0),
aspectRatioMode(Plasma::IgnoreAspectRatio), aspectRatioMode(Plasma::IgnoreAspectRatio),
resizeChecksWithBorderCheck(false) resizeChecksWithBorderCheck(false)
@ -72,6 +76,10 @@ public:
Dialog::ResizeCorners resizeCorners; Dialog::ResizeCorners resizeCorners;
QMap<Dialog::ResizeCorner, QRect> resizeAreas; QMap<Dialog::ResizeCorner, QRect> resizeAreas;
int resizeStartCorner; int resizeStartCorner;
int leftResizeMin;
int topResizeMin;
int rightResizeMin;
int bottomResizeMin;
QTimer *moveTimer; QTimer *moveTimer;
QTimer *adjustViewTimer; QTimer *adjustViewTimer;
QTimer *adjustSizeTimer; QTimer *adjustSizeTimer;