Skip to content

Commit

Permalink
fix: move the DAbstractDialog window is invalid
Browse files Browse the repository at this point in the history
Change-Id: Ifd1984173088453a93a5015325773ac2cf1a7126
  • Loading branch information
zccrs committed Mar 13, 2018
1 parent 8117bf7 commit 7d578e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/widgets/dabstractdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QLabel>
#include <QDebug>

#include "anchors.h"
#include "danchors.h"
#include "dialog_constants.h"
#include "dabstractdialog.h"
#include "private/dabstractdialogprivate_p.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ void DAbstractDialogPrivate::init()

windowTitle = new QLabel(q);
windowTitle->setAlignment(Qt::AlignCenter);
AnchorsBase::setAnchor(windowTitle, Qt::AnchorHorizontalCenter, q, Qt::AnchorHorizontalCenter);
DAnchorsBase::setAnchor(windowTitle, Qt::AnchorHorizontalCenter, q, Qt::AnchorHorizontalCenter);
q->connect(q,&QWidget::windowTitleChanged, windowTitle,[=](const QString &title){
windowTitle->setText(title);
});
Expand Down Expand Up @@ -149,6 +149,24 @@ DAbstractDialog::DisplayPostion DAbstractDialog::displayPostion() const
return static_cast<DisplayPostion>(displayPosition());
}

void DAbstractDialog::move(const QPoint &pos)
{
QDialog::move(pos);

D_D(DAbstractDialog);

d->mouseMoved = true;
}

void DAbstractDialog::setGeometry(const QRect &rect)
{
QDialog::setGeometry(rect);

D_D(DAbstractDialog);

d->mouseMoved = true;
}

/**
* @brief DAbstractDialog::moveToCenter moves the dialog to the center of the screen or its parent widget.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/dabstractdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class LIBDTKWIDGETSHARED_EXPORT DAbstractDialog : public QDialog, public DTK_COR
DisplayPosition displayPosition() const;
D_DECL_DEPRECATED DisplayPostion displayPostion() const;

void move(const QPoint &pos);
void setGeometry(const QRect &rect);

public Q_SLOTS:
void moveToCenter();
void moveToTopRight();
Expand Down
11 changes: 9 additions & 2 deletions src/widgets/danchors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,23 @@ bool DAnchorsBase::setAnchor(const Qt::AnchorPoint &p, QWidget *target, const Qt
}else{\
old_pos = d->getValueByInfo(d->point);\
int target_old_value = d->getValueByInfo(point);\
/*保存widget当然的一些标志位,setValueByInfo仅仅是尝试设置,调用之后要复原标志位*/\
bool moved = point->base->target()->testAttribute(Qt::WA_Moved);\
bool resized = point->base->target()->testAttribute(Qt::WA_Resized);\
d->setValueByInfo(target_old_value + 1, point);\
if(old_pos != d->getValueByInfo(d->point)){\
*d->point = old_info;\
slotName();\
d->setValueByInfo(target_old_value, point);\
point->base->target()->setAttribute(Qt::WA_Moved, moved);\
point->base->target()->setAttribute(Qt::WA_Resized, resized);\
d->errorCode = PointInvalid;\
d->errorString = "loop bind.";\
return false;\
}\
d->setValueByInfo(target_old_value, point);\
point->base->target()->setAttribute(Qt::WA_Moved, moved);\
point->base->target()->setAttribute(Qt::WA_Resized, resized);\
}\
tmp_w2 = point->base->d_func()->extendWidget;\
if(tmp_w1 != tmp_w2){\
Expand Down Expand Up @@ -929,12 +936,12 @@ void DAnchorsBase::setAlignWhenCentered(bool alignWhenCentered)
rect.set##fun(arg, point);\
target()->setMinimumSize(QSize(0,0));\
target()->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));\
target()->setGeometry(rect);\
target()->setGeometry(rect);

#define MOVE_POS(fun)\
DAnchorsRect rect = target()->geometry();\
rect.move##fun(arg);\
target()->move(rect.topLeft());\
target()->move(rect.topLeft());

void DAnchorsBase::setTop(int arg, Qt::AnchorPoint point)
{
Expand Down

0 comments on commit 7d578e9

Please sign in to comment.