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

📄 q3toolbar.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 "q3toolbar.h"#ifndef QT_NO_TOOLBAR#include "q3mainwindow.h"#include "qapplication.h"#include "qcombobox.h"#include "qcursor.h"#include "qdesktopwidget.h"#include "qdrawutil.h"#include "qevent.h"#include "qframe.h"#include "qlayout.h"#include "qmap.h"#include "qpainter.h"#include "q3popupmenu.h"#include "qstyle.h"#include "qstyleoption.h"#include "qtimer.h"#include "qtoolbutton.h"#include "qtooltip.h"static const char * const arrow_v_xpm[] = {    "7 9 3 1",    "            c None",    ".            c #000000",    "+            c none",    ".+++++.",    "..+++..",    "+..+..+",    "++...++",    ".++.++.",    "..+++..",    "+..+..+",    "++...++",    "+++.+++"};static const char * const arrow_h_xpm[] = {    "9 7 3 1",    "            c None",    ".            c #000000",    "+            c none",    "..++..+++",    "+..++..++",    "++..++..+",    "+++..++..",    "++..++..+",    "+..++..++",    "..++..+++"};class Q3ToolBarExtensionWidget;class Q3ToolBarPrivate{public:    Q3ToolBarPrivate() : moving(false), checkingExtension(false) {    }    bool moving;    bool checkingExtension;    Q3ToolBarExtensionWidget *extension;    Q3PopupMenu *extensionPopup;    QMap<QAction *, QWidget *> actions;};class Q3ToolBarSeparator : public QWidget{    Q_OBJECTpublic:    Q3ToolBarSeparator(Qt::Orientation, Q3ToolBar *parent, const char* name=0);    QSize sizeHint() const;    Qt::Orientation orientation() const { return orient; }public slots:    void setOrientation(Qt::Orientation);protected:    void changeEvent(QEvent *);    void paintEvent(QPaintEvent *);private:    Qt::Orientation orient;};class Q3ToolBarExtensionWidget : public QWidget{    Q_OBJECTpublic:    Q3ToolBarExtensionWidget(QWidget *w);    void setOrientation(Qt::Orientation o);    QToolButton *button() const { return tb; }protected:    void resizeEvent(QResizeEvent *e) {        QWidget::resizeEvent(e);        layOut();    }private:    void layOut();    QToolButton *tb;    Qt::Orientation orient;};Q3ToolBarExtensionWidget::Q3ToolBarExtensionWidget(QWidget *w)    : QWidget(w, "qt_dockwidget_internal"){    tb = new QToolButton(this, "qt_toolbar_ext_button");    tb->setAutoRaise(true);    setOrientation(Qt::Horizontal);    setAutoFillBackground(true);}void Q3ToolBarExtensionWidget::setOrientation(Qt::Orientation o){    orient = o;    if (orient == Qt::Horizontal)        tb->setIcon(QPixmap((const char **)arrow_h_xpm));    else        tb->setIcon(QPixmap((const char **)arrow_v_xpm));    layOut();}void Q3ToolBarExtensionWidget::layOut(){    tb->setGeometry(2, 2, width() - 4, height() - 4);}Q3ToolBarSeparator::Q3ToolBarSeparator(Qt::Orientation o , Q3ToolBar *parent,                                     const char* name)    : QWidget(parent, name){    connect(parent, SIGNAL(orientationChanged(Qt::Orientation)),             this, SLOT(setOrientation(Qt::Orientation)));    setOrientation(o);    setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));}void Q3ToolBarSeparator::setOrientation(Qt::Orientation o){    orient = o;}void Q3ToolBarSeparator::changeEvent(QEvent *ev){    if(ev->type() == QEvent::StyleChange)        setOrientation(orient);    QWidget::changeEvent(ev);}static QStyleOption getStyleOption(const Q3ToolBarSeparator *tbs){    QStyleOption opt(0);    opt.rect = tbs->rect();    opt.palette = tbs->palette();    if (tbs->orientation() == Qt::Horizontal)        opt.state = QStyle::State_Horizontal;    else        opt.state = QStyle::State_None;    return opt;}QSize Q3ToolBarSeparator::sizeHint() const{    QStyleOption opt = getStyleOption(this);    int extent = style()->pixelMetric(QStyle::PM_ToolBarSeparatorExtent, &opt, this);    if (orient == Qt::Horizontal)        return QSize(extent, 0);    else        return QSize(0, extent);}void Q3ToolBarSeparator::paintEvent(QPaintEvent *){    QPainter p(this);    QStyleOption opt = getStyleOption(this);    style()->drawPrimitive(QStyle::PE_Q3DockWindowSeparator, &opt, &p, this);}#include "q3toolbar.moc"/*!    \class Q3ToolBar    \brief The Q3ToolBar class provides a movable panel containing    widgets such as tool buttons.    \compat    A toolbar is a panel that contains a set of controls, usually    represented by small icons. It's purpose is to provide quick    access to frequently used commands or options. Within a    Q3MainWindow the user can drag toolbars within and between the    \link Q3DockArea dock areas\endlink. Toolbars can also be dragged    out of any dock area to float freely as top-level windows.    Q3ToolBar is a specialization of QDockWindow, and so provides all    the functionality of a QDockWindow.    To use Q3ToolBar you simply create a Q3ToolBar as a child of a    Q3MainWindow, create a number of QToolButton widgets (or other    widgets) in left to right (or top to bottom) order and call    addSeparator() when you want a separator. When a toolbar is    floated the caption used is the label given in the constructor    call. This can be changed with setLabel().    You may use most widgets within a toolbar, with QToolButton and    QComboBox being the most common. But note that the toolbar's    actions must be \l {Q3Action}s.    If you create a new widget on an already visible Q3ToolBar, this    widget will automatically become visible without needing a show()    call. (This differs from every other Qt widget container. We    recommend calling show() anyway since we hope to fix this anomaly    in a future release.)    Q3ToolBars, like QDockWindows, are located in \l{Q3DockArea}s or    float as top-level windows. Q3MainWindow provides four Q3DockAreas    (top, left, right and bottom). When you create a new toolbar (as    in the example above) as a child of a Q3MainWindow the toolbar will    be added to the top dock area. You can move it to another dock    area (or float it) by calling Q3MainWindow::moveDockWindow(). Dock    areas lay out their windows in lines.    If the main window is resized so that the area occupied by the    toolbar is too small to show all its widgets a little arrow button    (which looks like a right-pointing chevron, '&#187;') will appear    at the right or bottom of the toolbar depending on its    orientation. Clicking this button pops up a menu that shows the    'overflowing' items. QToolButtons are represented in the menu using    their textLabel property, other QAbstractButton subclasses are represented    using their text property, and QComboBoxes are represented as submenus,    with the caption text being used in the submenu item.    Usually a toolbar will get precisely the space it needs. However,    with setHorizontalStretchable(), setVerticalStretchable() or    setStretchableWidget() you can tell the main window to expand the    toolbar to fill all available space in the specified orientation.    The toolbar arranges its buttons either horizontally or vertically    (see orientation() for details). Generally, Q3DockArea will set the    orientation correctly for you, but you can set it yourself with    setOrientation() and track any changes by connecting to the    orientationChanged() signal.    You can use the clear() method to remove all items from a toolbar.    \img qdockwindow.png Toolbar (dock window)    \caption A floating QToolbar (dock window)    \sa QToolButton Q3MainWindow*//*!    Constructs an empty toolbar.    The toolbar is called \a name and is a child of \a parent and is    managed by \a parent. It is initially located in dock area \a dock    and is labeled \a label. If \a newLine is true the toolbar will be    placed on a new line in the dock area.*/Q3ToolBar::Q3ToolBar(const QString &label,                    Q3MainWindow * parent, Qt::ToolBarDock dock,                    bool newLine, const char * name)    : Q3DockWindow(InDock, parent, name, 0, true){    mw = parent;    init();    if (parent)        parent->addToolBar(this, label, dock, newLine);}/*!    Constructs an empty horizontal toolbar.    The toolbar is called \a name and is a child of \a parent and is    managed by \a mainWindow. The \a label and \a newLine parameters    are passed straight to Q3MainWindow::addDockWindow(). \a name and    the widget flags \a f are passed on to the Q3DockWindow constructor.    Use this constructor if you want to create torn-off (undocked,    floating) toolbars or toolbars in the \link QStatusBar status    bar\endlink.*/Q3ToolBar::Q3ToolBar(const QString &label, Q3MainWindow * mainWindow,                    QWidget * parent, bool newLine, const char * name,                    Qt::WindowFlags f)    : Q3DockWindow(InDock, parent, name, f, true){    mw = mainWindow;    init();    setParent(parent);    if (mainWindow)        mainWindow->addToolBar(this, label, Qt::DockUnmanaged, newLine);}/*!    \overload    Constructs an empty toolbar called \a name, with parent \a parent,    in its \a parent's top dock area, without any label and without    requiring a newline.*/Q3ToolBar::Q3ToolBar(Q3MainWindow * parent, const char * name)    : Q3DockWindow(InDock, parent, name, 0, true){    mw = parent;    init();    if (parent)        parent->addToolBar(this, QString(), Qt::DockTop);}/*!    \internal  Common initialization code. Requires that \c mw and \c o are set.  Does not call Q3MainWindow::addDockWindow().*/void Q3ToolBar::init(){    d = new Q3ToolBarPrivate;    d->extension = 0;    d->extensionPopup = 0;    sw = 0;    setBackgroundRole(QPalette::Button);    setFocusPolicy(Qt::NoFocus);    setFrameStyle(QFrame::ToolBarPanel | QFrame::Raised);}/*!    Destructor.*/Q3ToolBar::~Q3ToolBar(){    delete d;}/*!    \reimp*/void Q3ToolBar::setOrientation(Qt::Orientation o){    Q3DockWindow::setOrientation(o);    if (d->extension)        d->extension->setOrientation(o);    QObjectList childList = children();    for (int i = 0; i < childList.size(); ++i) {        Q3ToolBarSeparator* w = qobject_cast<Q3ToolBarSeparator*>(childList.at(i));        if (w)            w->setOrientation(o);    }}/*!    Adds a separator to the right/bottom of the toolbar.*/void Q3ToolBar::addSeparator(){    (void) new Q3ToolBarSeparator(orientation(), this, "toolbar separator");}/*!

⌨️ 快捷键说明

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