⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3tabdialog.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt3Support module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "q3tabdialog.h"#include "qtabbar.h"#include "qtabwidget.h"#include "qpushbutton.h"#include "qpainter.h"#include "qpixmap.h"#include "qapplication.h"#include "q3widgetstack.h"#include "qlayout.h"using namespace Qt;/*!    \class Q3TabDialog    \compat    \brief The Q3TabDialog class provides a stack of tabbed widgets.    A tabbed dialog is one in which several "tab pages" are available.    By clicking on a tab page's tab or by pressing the indicated    Alt+\e{letter} key combination, the user can select which tab page    they want to use.    Q3TabDialog provides a tab bar consisting of single row of tabs at    the top; each tab has an associated widget which is that tab's    tab page. In addition, Q3TabDialog provides an OK button and the    following optional buttons: Apply, Cancel, Defaults and Help.    The normal way to use Q3TabDialog is to do the following in the    constructor:    \list 1    \i Create a Q3TabDialog.    \i Create a QWidget for each of the pages in the tab dialog, insert    children into it, set up geometry management for it, and use    addTab() (or insertTab()) to set up a tab and keyboard accelerator    for it.    \i Set up the buttons for the tab dialog using setOkButton(),    setApplyButton(), setDefaultsButton(), setCancelButton() and    setHelpButton().    \i Connect to the signals and slots.    \endlist    If you don't call addTab() the page you have created will not be    visible. Don't confuse the object name you supply to the    QWidget constructor and the tab label you supply to addTab();    addTab() takes user-visible name that appears on the widget's tab    and may identify an accelerator, whereas the widget name is used    primarily for debugging.    Almost all applications have to connect the applyButtonPressed()    signal to something. applyButtonPressed() is emitted when either OK    or Apply is clicked, and your slot must copy the dialog's state into    the application.    There are also several other signals which may be useful:    \list    \i cancelButtonPressed() is emitted when the user clicks Cancel.    \i defaultButtonPressed() is emitted when the user clicks Defaults;    the slot it is connected to should reset the state of the dialog to    the application defaults.    \i helpButtonPressed() is emitted when the user clicks Help.    \i aboutToShow() is emitted at the start of show(); if there is any    chance that the state of the application may change between the    creation of the tab dialog and the time show() is called, you must    connect this signal to a slot that resets the state of the dialog.    \i currentChanged() is emitted when the user selects a page.    \endlist    Each tab is either enabled or disabled at any given time (see    setTabEnabled()). If a tab is enabled the tab text is drawn in    black and the user can select that tab. If it is disabled the tab    is drawn in a different way and the user cannot select that tab.    Note that even if a tab is disabled, the page can still be visible;    for example, if all of the tabs happen to be disabled.    You can change a tab's label and iconset using changeTab(). A tab    page can be removed with removePage() and shown with showPage(). The    current page is given by currentPage().    Q3TabDialog does not support tabs on the sides or bottom, nor can    you set or retrieve the visible page. If you need more functionality    than Q3TabDialog provides, consider creating a QDialog and using a    QTabBar with QTabWidgets.    Most of the functionality in Q3TabDialog is provided by a QTabWidget.*//*!    \fn void Q3TabDialog::selected(const QString &name)    This signal is emitted whenever a tab is selected (raised),    including during the first show(). \a name is the name of the    selected tab.    \sa raise()*//*! \fn void Q3TabDialog::currentChanged(QWidget *widget)    This signal is emitted whenever the current page changes. \a widget    is the new current page.    \sa currentPage(), showPage(), tabLabel()*/class Q3TabDialogPrivate{public:    Q3TabDialogPrivate();    QTabWidget* tw;    QPushButton * ok;    QPushButton * cb;    QPushButton * db;    QPushButton * hb;    QPushButton * ab;    QBoxLayout * tll;};Q3TabDialogPrivate::Q3TabDialogPrivate()	: tw(0),	  ok(0), cb(0), db(0), hb(0), ab(0),	  tll(0){ }/*!  Constructs a Q3TabDialog with only an OK button.  The \a parent, \a name, \a modal and widget flag, \a f, arguments  are passed on to the QDialog constructor.*/Q3TabDialog::Q3TabDialog(QWidget *parent, const char *name, bool modal, Qt::WindowFlags f)    : QDialog(parent, name, modal, f){    d = new Q3TabDialogPrivate;    Q_CHECK_PTR(d);    d->tw = new QTabWidget(this, "tab widget");    connect (d->tw, SIGNAL (selected(QString)), this, SIGNAL(selected(QString)));    connect (d->tw, SIGNAL (currentChanged(QWidget*)), this, SIGNAL(currentChanged(QWidget*)));    d->ok = new QPushButton(this, "ok");    Q_CHECK_PTR(d->ok);    d->ok->setText(tr("OK"));    d->ok->setDefault(true);    connect(d->ok, SIGNAL(clicked()),	     this, SIGNAL(applyButtonPressed()));    connect(d->ok, SIGNAL(clicked()),	     this, SLOT(accept()));}/*!  Destroys the tab dialog.*/Q3TabDialog::~Q3TabDialog(){    delete d;}/*!  Sets the font for the tabs to \a font.  If the widget is visible, the display is updated with the new font  immediately. There may be some geometry changes, depending on the  size of the old and new fonts.*/void Q3TabDialog::setFont(const QFont & font){    QDialog::setFont(font);    setSizes();}/*!  \fn void Q3TabDialog::applyButtonPressed();  This signal is emitted when either the Apply or OK button is clicked.  It should be connected to a slot (or several slots) that change the  application's state according to the state of the dialog.  \sa cancelButtonPressed() defaultButtonPressed() setApplyButton()*//*!  Returns true if the tab dialog has a Defaults button; otherwise  returns false.  \sa setDefaultButton() defaultButtonPressed() hasApplyButton()  hasCancelButton()*/bool Q3TabDialog::hasDefaultButton() const{     return d->db != 0;}/*!  Returns true if the tab dialog has a Help button; otherwise returns  false.  \sa setHelpButton() helpButtonPressed() hasApplyButton()  hasCancelButton()*/bool Q3TabDialog::hasHelpButton() const{     return d->hb != 0;}/*!  \fn void Q3TabDialog::cancelButtonPressed();  This signal is emitted when the Cancel button is clicked. It is  automatically connected to QDialog::reject(), which will hide the  dialog.  The Cancel button should not change the application's state at all,  so you should generally not need to connect it to any slot.  \sa applyButtonPressed() defaultButtonPressed() setCancelButton()*//*!  Returns true if the tab dialog has a Cancel button; otherwise  returns false.  \sa setCancelButton() cancelButtonPressed() hasApplyButton()  hasDefaultButton()*/bool Q3TabDialog::hasCancelButton() const{     return d->cb != 0;}/*!  \fn void Q3TabDialog::defaultButtonPressed();  This signal is emitted when the Defaults button is pressed. It  should reset the dialog (but not the application) to the "factory  defaults".  The application's state should not be changed until the user clicks  Apply or OK.  \sa applyButtonPressed() cancelButtonPressed() setDefaultButton()*//*!  \fn void Q3TabDialog::helpButtonPressed();  This signal is emitted when the Help button is pressed. It  could be used to present information about how to use the dialog.  \sa applyButtonPressed() cancelButtonPressed() setHelpButton()*//*!  Returns true if the tab dialog has an Apply button; otherwise  returns false.  \sa setApplyButton() applyButtonPressed() hasCancelButton()  hasDefaultButton()*/bool Q3TabDialog::hasApplyButton() const{    return d->ab != 0;}/*!  Returns true if the tab dialog has an OK button; otherwise returns  false.  \sa setOkButton() hasApplyButton() hasCancelButton()  hasDefaultButton()*/bool Q3TabDialog::hasOkButton() const{    return d->ok != 0;}/*!  \fn void Q3TabDialog::aboutToShow()  This signal is emitted by show() when it is time to set the state of  the dialog's contents. The dialog should reflect the current state  of the application when it appears; if there is any possibility that  the state of the application may change between the time you call  Q3TabDialog() and show(), you should set the  dialog's state in a slot and connect this signal to it.  This applies mainly to Q3TabDialog objects that are kept around  hidden, rather than being created, shown, and deleted afterwards.  \sa applyButtonPressed(), QWidget::show(), cancelButtonPressed()*//*!    \internal    Implemented to delay show()'ing of every page.*/void Q3TabDialog::show(){    //   Reimplemented in order to delay show()'ing of every page    //   except the initially visible one, and in order to emit the    //   aboutToShow() signal.    if (window() == this)	d->tw->setFocus();    emit aboutToShow();    setSizes();    setUpLayout();    QDialog::show();}/*!  Adds another tab and page to the tab view.  The new page is \a child; the tab's label is \a label.  Note the difference between the widget name (which you supply to  widget constructors and to setTabEnabled(), for example) and the tab  label. The name is internal to the program and invariant, whereas  the label is shown on-screen and may vary according to language and  other factors.  If the tab's \a label contains an ampersand, the letter following  the ampersand is used as an accelerator for the tab, e.g. if the  label is "Bro&wse" then Alt+W becomes an accelerator which will  move the focus to this tab.  If you call addTab() after show() the screen will flicker and the  user may be confused.  \sa insertTab()*/void Q3TabDialog::addTab(QWidget * child, const QString &label){    d->tw->addTab(child, label);}/*! \overload  This version of the function shows the \a iconset as well as the \a  label on the tab of \a child.*/void Q3TabDialog::addTab(QWidget *child, const QIcon& iconset, const QString &label){    d->tw->addTab(child, iconset, label);}/*!  Inserts another tab and page to the tab view.  The new page is \a child; the tab's label is \a label.  Note the difference between the widget name (which you supply to  widget constructors and to setTabEnabled(), for example) and the tab  label. The name is internal to the program and invariant, whereas  the label is shown on-screen and may vary according to language and  other factors.  If the tab's \a label contains an ampersand, the letter following  the ampersand is used as an accelerator for the tab, e.g. if the  label is "Bro&wse" then Alt+W becomes an accelerator which will  move the focus to this tab.  If \a index is not specified, the tab is simply added. Otherwise  it is inserted at the specified position.  If you call insertTab() after show(), the screen will flicker and the  user may be confused.  \sa addTab()*/void Q3TabDialog::insertTab(QWidget * child, const QString &label, int index){    d->tw->insertTab(child, label, index);}/*! \overload  This version of the function shows the \a iconset as well as the \a  label on the tab of \a child. */void Q3TabDialog::insertTab(QWidget *child, const QIcon& iconset, const QString &label, int index){    d->tw->insertTab(child, iconset, label, index);}/*!  Replaces the QTabBar heading the dialog by the given tab bar, \a tb.  Note that this must be called \e before any tabs have been added,  or the behavior is undefined.  \sa tabBar()*/void Q3TabDialog::setTabBar(QTabBar* tb){    if (tb == 0){        qWarning("Q3TabDialog::setTabBar() called with null QTabBar pointer");        return;    }        d->tw->setTabBar(tb);    setUpLayout();}/*!  Returns the currently set QTabBar.  \sa setTabBar()*/QTabBar* Q3TabDialog::tabBar() const{    return d->tw->tabBar();}/*!  Ensures that widget \a w is shown. This is mainly useful for accelerators.  \warning If used carelessly, this function can easily surprise or  confuse the user.  \sa QTabBar::setCurrentTab()*/void Q3TabDialog::showPage(QWidget * w){    d->tw->showPage(w);}/*! \obsolete  Returns true if the page with object name \a name is enabled and  false if it is disabled.  If \a name is 0 or not the name of any of the pages, isTabEnabled()  returns false.  \sa setTabEnabled(), QWidget::isEnabled()*/bool Q3TabDialog::isTabEnabled(const char* name) const{    if (!name)	return false;    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())                continue;            QWidget *w = static_cast<QWidget *>(o);            return d->tw->isTabEnabled(w);        }    }    return false;}/*!\obsolete  Finds the page with object name \a name, enables/disables it  according to the value of \a enable and redraws the page's tab  appropriately.  Q3TabDialog uses QWidget::setEnabled() internally, rather than keeping a  separate flag.  Note that even a disabled tab/page may be visible. If the page is  already visible Q3TabDialog will not hide it; if all the pages  are disabled Q3TabDialog will show one of them.  The object name is used (rather than the tab label) because the tab  text may not be invariant in multi-language applications.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -