📄 qdialog.cpp
字号:
#ifdef Q_WS_X11 // if the WM advertises that it will place the windows properly for us, let it do it :) if (X11->isSupportedByWM(ATOM(_NET_WM_FULL_PLACEMENT))) return;#endif QPoint p(0, 0); int extraw = 0, extrah = 0, scrn = 0; if (w) w = w->window(); QRect desk; if (w) { scrn = QApplication::desktop()->screenNumber(w); } else if (QApplication::desktop()->isVirtualDesktop()) { scrn = QApplication::desktop()->screenNumber(QCursor::pos()); } else { scrn = QApplication::desktop()->screenNumber(this); } desk = QApplication::desktop()->availableGeometry(scrn); QWidgetList list = QApplication::topLevelWidgets(); for (int i = 0; (extraw == 0 || extrah == 0) && i < list.size(); ++i) { QWidget * current = list.at(i); if (current->isVisible()) { int framew = current->geometry().x() - current->x(); int frameh = current->geometry().y() - current->y(); extraw = qMax(extraw, framew); extrah = qMax(extrah, frameh); } } // sanity check for decoration frames. With embedding, we // might get extraordinary values if (extraw == 0 || extrah == 0 || extraw >= 10 || extrah >= 40) { extrah = 40; extraw = 10; }#ifndef Q_OS_TEMP if (w) { // Use mapToGlobal rather than geometry() in case w might // be embedded in another application QPoint pp = w->mapToGlobal(QPoint(0,0)); p = QPoint(pp.x() + w->width()/2, pp.y() + w->height()/ 2); } else { // p = middle of the desktop p = QPoint(desk.x() + desk.width()/2, desk.y() + desk.height()/2); }#else p = QPoint(desk.x() + desk.width()/2, desk.y() + desk.height()/2);#endif // p = origin of this p = QPoint(p.x()-width()/2 - extraw, p.y()-height()/2 - extrah); if (p.x() + extraw + width() > desk.x() + desk.width()) p.setX(desk.x() + desk.width() - width() - extraw); if (p.x() < desk.x()) p.setX(desk.x()); if (p.y() + extrah + height() > desk.y() + desk.height()) p.setY(desk.y() + desk.height() - height() - extrah); if (p.y() < desk.y()) p.setY(desk.y()); move(p);}/*! \obsolete If \a orientation is Qt::Horizontal, the extension will be displayed to the right of the dialog's main area. If \a orientation is Qt::Vertical, the extension will be displayed below the dialog's main area. Instead of using this functionality, we recommend that you simply call show() or hide() on the part of the dialog that you want to use as an extension. See the \l{Extension Example} for details. \sa setExtension()*/void QDialog::setOrientation(Qt::Orientation orientation){ Q_D(QDialog); d->orientation = orientation;}/*! \obsolete Returns the dialog's extension orientation. Instead of using this functionality, we recommend that you simply call show() or hide() on the part of the dialog that you want to use as an extension. See the \l{Extension Example} for details. \sa extension()*/Qt::Orientation QDialog::orientation() const{ Q_D(const QDialog); return d->orientation;}/*! \obsolete Sets the widget, \a extension, to be the dialog's extension, deleting any previous extension. The dialog takes ownership of the extension. Note that if 0 is passed any existing extension will be deleted. This function must only be called while the dialog is hidden. Instead of using this functionality, we recommend that you simply call show() or hide() on the part of the dialog that you want to use as an extension. See the \l{Extension Example} for details. \sa showExtension(), setOrientation()*/void QDialog::setExtension(QWidget* extension){ Q_D(QDialog); delete d->extension; d->extension = extension; if (!extension) return; if (extension->parentWidget() != this) extension->setParent(this); extension->hide();}/*! \obsolete Returns the dialog's extension or 0 if no extension has been defined. Instead of using this functionality, we recommend that you simply call show() or hide() on the part of the dialog that you want to use as an extension. See the \l{Extension Example} for details. \sa showExtension(), setOrientation()*/QWidget* QDialog::extension() const{ Q_D(const QDialog); return d->extension;}/*! \obsolete If \a showIt is true, the dialog's extension is shown; otherwise the extension is hidden. Instead of using this functionality, we recommend that you simply call show() or hide() on the part of the dialog that you want to use as an extension. See the \l{Extension Example} for details. \sa show(), setExtension(), setOrientation()*/void QDialog::showExtension(bool showIt){ Q_D(QDialog); d->doShowExtension = showIt; if (!d->extension) return; if (!testAttribute(Qt::WA_WState_Visible)) return; if (d->extension->isVisible() == showIt) return; if (showIt) { d->size = size(); d->min = minimumSize(); d->max = maximumSize(); if (layout()) layout()->setEnabled(false); QSize s(d->extension->sizeHint() .expandedTo(d->extension->minimumSize()) .boundedTo(d->extension->maximumSize())); if (d->orientation == Qt::Horizontal) { int h = qMax(height(), s.height()); d->extension->setGeometry(width(), 0, s.width(), h); setFixedSize(width() + s.width(), h); } else { int w = qMax(width(), s.width()); d->extension->setGeometry(0, height(), w, s.height()); setFixedSize(w, height() + s.height()); } d->extension->show();#ifndef QT_NO_SIZEGRIP const bool sizeGripEnabled = isSizeGripEnabled(); setSizeGripEnabled(false); d->sizeGripEnabled = sizeGripEnabled;#endif } else { d->extension->hide(); // workaround for CDE window manager that won't shrink with (-1,-1) setMinimumSize(d->min.expandedTo(QSize(1, 1))); setMaximumSize(d->max); resize(d->size); if (layout()) layout()->setEnabled(true);#ifndef QT_NO_SIZEGRIP setSizeGripEnabled(d->sizeGripEnabled);#endif }}/*! \reimp */QSize QDialog::sizeHint() const{ Q_D(const QDialog); if (d->extension) if (d->orientation == Qt::Horizontal) return QSize(QWidget::sizeHint().width(), qMax(QWidget::sizeHint().height(),d->extension->sizeHint().height())); else return QSize(qMax(QWidget::sizeHint().width(), d->extension->sizeHint().width()), QWidget::sizeHint().height()); return QWidget::sizeHint();}/*! \reimp */QSize QDialog::minimumSizeHint() const{ Q_D(const QDialog); if (d->extension) if (d->orientation == Qt::Horizontal) return QSize(QWidget::minimumSizeHint().width(), qMax(QWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height())); else return QSize(qMax(QWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width()), QWidget::minimumSizeHint().height()); return QWidget::minimumSizeHint();}/*! \property QDialog::modal \brief whether show() should pop up the dialog as modal or modeless By default, this property is false and show() pops up the dialog as modeless. Setting his property to true is equivalent to setting QWidget::windowModality to Qt::ApplicationModal. exec() ignores the value of this property and always pops up the dialog as modal. \sa QWidget::windowModality, show(), exec()*/void QDialog::setModal(bool modal){ setAttribute(Qt::WA_ShowModal, modal);}bool QDialog::isSizeGripEnabled() const{#ifndef QT_NO_SIZEGRIP Q_D(const QDialog); return !!d->resizer;#else return false;#endif}void QDialog::setSizeGripEnabled(bool enabled){#ifdef QT_NO_SIZEGRIP Q_UNUSED(enabled);#else Q_D(QDialog);#ifndef QT_NO_SIZEGRIP d->sizeGripEnabled = enabled; if (enabled && d->doShowExtension) return;#endif if (!enabled != !d->resizer) { if (enabled) { d->resizer = new QSizeGrip(this); // adjustSize() processes all events, which is suboptimal d->resizer->resize(d->resizer->sizeHint()); if (isRightToLeft()) d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft()); else d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight()); d->resizer->lower(); d->resizer->show(); } else { delete d->resizer; d->resizer = 0; } }#endif //QT_NO_SIZEGRIP}/*! \reimp */void QDialog::resizeEvent(QResizeEvent *){#ifndef QT_NO_SIZEGRIP Q_D(QDialog); if (d->resizer) { if (isRightToLeft()) d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft()); else d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight()); d->resizer->lower(); }#endif}/*! \fn void QDialog::finished(int result) \since 4.1 This signal is emitted when the dialog's \a result code has been set, either by the user or by calling done(), accept(), or reject(). Note that this signal is \e not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible. \sa accepted(), rejected()*//*! \fn void QDialog::accepted() \since 4.1 This signal is emitted when the dialog has been accepted either by the user or by calling accept() or done() with the QDialog::Accepted argument. Note that this signal is \e not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible. \sa finished(), rejected()*//*! \fn void QDialog::rejected() \since 4.1 This signal is emitted when the dialog has been rejected either by the user or by calling reject() or done() with the QDialog::Rejected argument. Note that this signal is \e not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible. \sa finished(), accepted()*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -