📄 q3tabdialog.cpp
字号:
\sa isTabEnabled(), QWidget::setEnabled()*/void Q3TabDialog::setTabEnabled(const char* name, bool enable){ if (!name) return; QObjectList l = this->queryList("QWidget", name, false, true); if (!l.isEmpty()) { for (int i = 0; i < l.size(); ++i) { QObject *o = l.at(i); if(o->isWidgetType()) d->tw->setTabEnabled(static_cast<QWidget*>(o), enable); } }}/* ### SHOULD THIS BE HERE? Adds an Apply button to the dialog. The button's text is set to \e text (and defaults to "Apply"). The Apply button should apply the current settings in the dialog box to the application, while keeping the dialog visible. When Apply is clicked, the applyButtonPressed() signal is emitted. If \a text is an empty string, no button is shown. \sa setCancelButton() setDefaultButton() applyButtonPressed()*//*! Returns true if the page \a w is enabled; otherwise returns false. \sa setTabEnabled(), QWidget::isEnabled()*/bool Q3TabDialog::isTabEnabled(QWidget* w) const{ return d->tw->isTabEnabled(w);}/*! If \a enable is true the page \a w is enabled; otherwise \a w is disabled. The page's tab is redrawn appropriately. QTabWidget uses QWidget::setEnabled() internally, rather than keeping a separate flag. Note that even a disabled tab and tab page may be visible. If the page is already visible QTabWidget will not hide it; if all the pages are disabled QTabWidget will show one of them. \sa isTabEnabled(), QWidget::setEnabled()*/void Q3TabDialog::setTabEnabled(QWidget* w, bool enable){ d->tw->setTabEnabled(w, enable);}/*! Adds an Apply button to the dialog. The button's text is set to \a text. The Apply button should apply the current settings in the dialog box to the application while keeping the dialog visible. When Apply is clicked, the applyButtonPressed() signal is emitted. If \a text is an empty string, no button is shown. \sa setCancelButton() setDefaultButton() applyButtonPressed()*/void Q3TabDialog::setApplyButton(const QString &text){ if (text.isEmpty() && d->ab) { delete d->ab; d->ab = 0; setSizes(); } else { if (!d->ab) { d->ab = new QPushButton(this, "apply settings"); connect(d->ab, SIGNAL(clicked()), this, SIGNAL(applyButtonPressed())); setUpLayout(); } d->ab->setText(text); setSizes(); //d->ab->show(); }}/*! \overload Adds an Apply button to the dialog. The button's text is set to a localizable "Apply". */void Q3TabDialog::setApplyButton(){ setApplyButton(tr("Apply"));}/*! Adds a Help button to the dialog. The button's text is set to \a text. When Help is clicked, the helpButtonPressed() signal is emitted. If \a text is an empty string, no button is shown. \sa setApplyButton() setCancelButton() helpButtonPressed()*/void Q3TabDialog::setHelpButton(const QString &text){ if (text.isEmpty()) { delete d->hb; d->hb = 0; setSizes(); } else { if (!d->hb) { d->hb = new QPushButton(this, "give help"); connect(d->hb, SIGNAL(clicked()), this, SIGNAL(helpButtonPressed())); setUpLayout(); } d->hb->setText(text); setSizes(); //d->hb->show(); }}/*! \overload Adds a Help button to the dialog. The button's text is set to a localizable "Help". */void Q3TabDialog::setHelpButton(){ setHelpButton(tr("Help"));}/*! Adds a Defaults button to the dialog. The button's text is set to \a text. The Defaults button should set the dialog (but not the application) back to the application defaults. When Defaults is clicked, the defaultButtonPressed() signal is emitted. If \a text is an empty string, no button is shown. \sa setApplyButton() setCancelButton() defaultButtonPressed()*/void Q3TabDialog::setDefaultButton(const QString &text){ if (text.isEmpty()) { delete d->db; d->db = 0; setSizes(); } else { if (!d->db) { d->db = new QPushButton(this, "back to default"); connect(d->db, SIGNAL(clicked()), this, SIGNAL(defaultButtonPressed())); setUpLayout(); } d->db->setText(text); setSizes(); //d->db->show(); }}/*! \overload Adds a Defaults button to the dialog. The button's text is set to a localizable "Defaults". */void Q3TabDialog::setDefaultButton(){ setDefaultButton(tr("Defaults"));}/*! Adds a Cancel button to the dialog. The button's text is set to \a text. The cancel button should always return the application to the state it was in before the tab view popped up, or if the user has clicked Apply, back to the state immediately after the last Apply. When Cancel is clicked, the cancelButtonPressed() signal is emitted. The dialog is closed at the same time. If \a text is an empty string, no button is shown. \sa setApplyButton() setDefaultButton() cancelButtonPressed()*/void Q3TabDialog::setCancelButton(const QString &text){ if (text.isEmpty()) { delete d->cb; d->cb = 0; setSizes(); } else { if (!d->cb) { d->cb = new QPushButton(this, "cancel dialog"); connect(d->cb, SIGNAL(clicked()), this, SIGNAL(cancelButtonPressed())); connect(d->cb, SIGNAL(clicked()), this, SLOT(reject())); setUpLayout(); } d->cb->setText(text); setSizes(); //d->cb->show(); }}/*! \overload Adds a Cancel button to the dialog. The button's text is set to a localizable "Cancel". */void Q3TabDialog::setCancelButton(){ setCancelButton(tr("Cancel"));}/*! Sets up the layout manager for the tab dialog. \sa setSizes() setApplyButton() setCancelButton() setDefaultButton()*/void Q3TabDialog::setUpLayout(){ // the next four are probably the same, really? const int topMargin = 6; const int leftMargin = 6; const int rightMargin = 6; const int bottomMargin = 6; const int betweenButtonsMargin = 7; const int aboveButtonsMargin = 8; delete d->tll; d->tll = new QBoxLayout(this, QBoxLayout::Down); // top margin d->tll->addSpacing(topMargin); QBoxLayout * tmp = new QHBoxLayout(); d->tll->addLayout(tmp, 1); tmp->addSpacing(leftMargin); tmp->addWidget(d->tw, 1); tmp->addSpacing(rightMargin + 2); d->tll->addSpacing(aboveButtonsMargin + 2); QBoxLayout * buttonRow = new QBoxLayout(QBoxLayout::RightToLeft); d->tll->addLayout(buttonRow, 0); d->tll->addSpacing(bottomMargin); buttonRow->addSpacing(rightMargin); if (d->cb) { buttonRow->addWidget(d->cb, 0); buttonRow->addSpacing(betweenButtonsMargin); d->cb->raise(); } if (d->ab) { buttonRow->addWidget(d->ab, 0); buttonRow->addSpacing(betweenButtonsMargin); d->ab->raise(); } if (d->db) { buttonRow->addWidget(d->db, 0); buttonRow->addSpacing(betweenButtonsMargin); d->db->raise(); } if (d->hb) { buttonRow->addWidget(d->hb, 0); buttonRow->addSpacing(betweenButtonsMargin); d->hb->raise(); } if (d->ok) { buttonRow->addWidget(d->ok, 0); buttonRow->addSpacing(betweenButtonsMargin); d->ok->raise(); } // add one custom widget here buttonRow->addStretch(1); // add another custom widget here d->tll->activate();}/*! Sets up the minimum and maximum sizes for each child widget. \sa setUpLayout() setFont()*/void Q3TabDialog::setSizes(){ // compute largest button size QSize s(0, 0); int bw = s.width(); int bh = s.height(); if (d->ok) { s = d->ok->sizeHint(); if (s.width() > bw) bw = s.width(); if (s.height() > bh) bh = s.height(); } if (d->ab) { s = d->ab->sizeHint(); if (s.width() > bw) bw = s.width(); if (s.height() > bh) bh = s.height(); } if (d->db) { s = d->db->sizeHint(); if (s.width() > bw) bw = s.width(); if (s.height() > bh) bh = s.height(); } if (d->hb) { s = d->hb->sizeHint(); if (s.width() > bw) bw = s.width(); if (s.height() > bh) bh = s.height(); } if (d->cb) { s = d->cb->sizeHint(); if (s.width() > bw) bw = s.width(); if (s.height() > bh) bh = s.height(); } // and set all the buttons to that size if (d->ok) d->ok->setFixedSize(bw, bh); if (d->ab) d->ab->setFixedSize(bw, bh); if (d->db) d->db->setFixedSize(bw, bh); if (d->hb) d->hb->setFixedSize(bw, bh); if (d->cb) d->cb->setFixedSize(bw, bh); // fiddle the tab chain so the buttons are in their natural order QWidget * w = d->ok; if (d->hb) { if (w) setTabOrder(w, d->hb); w = d->hb; } if (d->db) { if (w) setTabOrder(w, d->db); w = d->db; } if (d->ab) { if (w) setTabOrder(w, d->ab); w = d->ab; } if (d->cb) { if (w) setTabOrder(w, d->cb); w = d->cb; } setTabOrder(w, d->tw);}/*!\reimp*/void Q3TabDialog::resizeEvent(QResizeEvent * e){ QDialog::resizeEvent(e);}/*!\reimp*/void Q3TabDialog::paintEvent(QPaintEvent *){}/*! Adds an OK button to the dialog and sets the button's text to \a text. When the OK button is clicked, the applyButtonPressed() signal is emitted, and the current settings in the dialog box should be applied to the application. The dialog then closes. If \a text is an empty string, no button is shown. \sa setCancelButton() setDefaultButton() applyButtonPressed()*/void Q3TabDialog::setOkButton(const QString &text){ if (text.isEmpty()) { delete d->ok; d->ok = 0; setSizes(); } else { if (!d->ok) { d->ok = new QPushButton(this, "ok"); connect(d->ok, SIGNAL(clicked()), this, SIGNAL(applyButtonPressed())); setUpLayout(); } d->ok->setText(text); setSizes(); //d->ok->show(); }}/*! \overload Adds an OK button to the dialog. The button's text is set to a localizable "OK". */void Q3TabDialog::setOkButton(){ setOkButton(tr("OK"));}/* \overload Old version of setOkButton(), provided for backward compatibility.*/void Q3TabDialog::setOKButton(const QString &text){ // Ugly workaround for original "OK" default argument QString newText(text); if (text.isNull()) newText = QString::fromLatin1("OK"); setOkButton(newText);}/*! Returns the text in the tab for page \a w.*/QString Q3TabDialog::tabLabel(QWidget * w){ return d->tw->tabLabel(w);}/*! \reimp*/void Q3TabDialog::styleChange(QStyle& s){ QDialog::styleChange(s); setSizes();}/*! Returns a pointer to the page currently being displayed by thetab dialog. The tab dialog does its best to make sure that this valueis never 0 (but if you try hard enough, it can be).*/QWidget * Q3TabDialog::currentPage() const{ return d->tw->currentPage();}/*! \overload Defines a new \a label for the tab of page \a w */void Q3TabDialog::changeTab(QWidget *w, const QString &label){ d->tw->changeTab(w, label);}/*! Changes tab page \a w's iconset to \a iconset and label to \a label. */void Q3TabDialog::changeTab(QWidget *w, const QIcon& iconset, const QString &label){ d->tw->changeTab(w, iconset, label);}/*! Removes page \a w from this stack of widgets. Does not delete \a w. \sa showPage(), QTabWidget::removePage()*/void Q3TabDialog::removePage(QWidget * w){ d->tw->removePage(w);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -