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:
parent
64373cf1da
commit
d6e06ff92d
57
dialog.cpp
57
dialog.cpp
@ -490,8 +490,27 @@ void Dialog::mouseMoveEvent(QMouseEvent *event)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((newWidth >= minimumSize().width()) && (newHeight >= minimumSize().height())) {
|
||||
setGeometry(QRect(position, QSize(newWidth, newHeight)));
|
||||
QRect newGeom(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)
|
||||
{
|
||||
if (d->resizeStartCorner != Dialog::NoCorner) {
|
||||
emit dialogResized();
|
||||
d->resizeStartCorner = Dialog::NoCorner;
|
||||
unsetCursor();
|
||||
emit dialogResized();
|
||||
}
|
||||
|
||||
QWidget::mouseReleaseEvent(event);
|
||||
@ -745,6 +764,38 @@ Dialog::ResizeCorners Dialog::resizeCorners() const
|
||||
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)
|
||||
{
|
||||
if (!isVisible()) {
|
||||
|
25
dialog.h
25
dialog.h
@ -97,6 +97,31 @@ class PLASMA_EXPORT Dialog : public QWidget
|
||||
*/
|
||||
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
|
||||
* the dialog will simply hide.
|
||||
|
@ -40,6 +40,10 @@ public:
|
||||
view(0),
|
||||
resizeCorners(Dialog::NoCorner),
|
||||
resizeStartCorner(Dialog::NoCorner),
|
||||
leftResizeMin(-1),
|
||||
topResizeMin(-1),
|
||||
rightResizeMin(-1),
|
||||
bottomResizeMin(-1),
|
||||
moveTimer(0),
|
||||
aspectRatioMode(Plasma::IgnoreAspectRatio),
|
||||
resizeChecksWithBorderCheck(false)
|
||||
@ -72,6 +76,10 @@ public:
|
||||
Dialog::ResizeCorners resizeCorners;
|
||||
QMap<Dialog::ResizeCorner, QRect> resizeAreas;
|
||||
int resizeStartCorner;
|
||||
int leftResizeMin;
|
||||
int topResizeMin;
|
||||
int rightResizeMin;
|
||||
int bottomResizeMin;
|
||||
QTimer *moveTimer;
|
||||
QTimer *adjustViewTimer;
|
||||
QTimer *adjustSizeTimer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user