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

📄 qmainwindow.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    QMainWindow *win;    int pressedHandle;    bool pressed;#ifndef QT_NO_TOOLTIP    QHideToolTip *tip;    friend class QHideToolTip;#endif};#ifndef QT_NO_TOOLTIPvoid QHideToolTip::maybeTip( const QPoint &pos ){    if ( !parentWidget() )	return;    QHideDock *dock = (QHideDock*)parentWidget();    if ( !dock->d->hidden || dock->d->hidden->isEmpty() )	return;    QMainWindowPrivate::ToolBar *tb;    int x = 0;    int i = 0;    for ( tb = dock->d->hidden->first(); tb; tb = dock->d->hidden->next(), ++i ) {	if ( !tb->t->isVisible() )	    continue;	if ( pos.x() >= x && pos.x() <= x + 30 ) {	    if ( !tb->t->label().isEmpty() )		tip( QRect( x, 0, 30, dock->height() ), tb->t->label() );	    return;	}	x += 30;    }}#endif//************************************************************************************************// ------------------------ static internal functions  -----------------------//************************************************************************************************static QRect findRectInDockingArea( QMainWindowPrivate *d, QMainWindow::ToolBarDock dock,				    const QPoint &pos, QToolBar *tb ){    Qt::Orientation o = dock == QMainWindow::Top || dock == QMainWindow::Bottom ?			Qt::Horizontal : Qt::Vertical;    bool swap = o != tb->orientation();    QPoint offset( 0, 0 );    if ( swap ) {	if ( o == Qt::Horizontal )	    offset = QPoint( tb->height() / 2, 0 );	else	    offset = QPoint( 0, tb->width() / 2 );    }    return QRect( pos - d->cursorOffset - offset,		  swap ? QSize( tb->height(), tb->width() ) : tb->size() );}static void saveToolLayout( QMainWindowPrivate *d, QMainWindow::ToolBarDock dock, QToolBar *tb ){    QMainWindowPrivate::ToolBarDock * dl = 0;    switch ( dock ) {    case QMainWindow::Left:	dl = d->left;	break;    case QMainWindow::Right:	dl = d->right;	break;    case QMainWindow::Top:	dl = d->top;	break;    case QMainWindow::Bottom:	dl = d->bottom;	break;    case QMainWindow::Unmanaged:	dl = d->unmanaged;	break;    case QMainWindow::Minimized:	dl = d->hidden;	break;    case QMainWindow::TornOff:	dl = d->tornOff;	break;    }    if ( !dl )	return;    QMainWindowPrivate::ToolBarDock *dummy;    QMainWindowPrivate::ToolBar *t = 0;    t = d->findToolbar( tb, dummy );    int i = dl->findRef( t );    if ( i == -1 )	return;    if ( i + 1 < (int)dl->count() && !dl->at( i + 1 )->nl ) {	if ( t->nl )	    dl->at( i + 1 )->nl = t->nl;	else if ( i - 1 >= 0 )	    dl->at( i + 1 )->nl = tb_pos( dl->at( i - 1 )->t, dl->at( i - 1 )->t->orientation(), TRUE ) !=				  tb_pos( dl->at( i + 1 )->t, dl->at( i + 1 )->t->orientation(), TRUE );    }}static void findNewToolbarPlace( QMainWindowPrivate *d, QToolBar *tb, QMainWindow::ToolBarDock dock,				 const QRect &dockArea, QToolBar *&relative, int &ipos ){    relative = 0;    Qt::Orientation o = dock == QMainWindow::Top || dock == QMainWindow::Bottom ?			Qt::Horizontal : Qt::Vertical;    QMainWindowPrivate::ToolBarDock * dl = 0;    int dy = 0;    switch ( dock ) {    case QMainWindow::Left:	dl = d->left;	if ( d->lLeft )	    dy = d->lLeft->geometry().y() + ( d->top && !d->top->isEmpty() ? 8 : 0 );	if ( d->lLeft && d->lastTopHeight != -1 && !dy )	    dy = d->lastTopHeight;	else	    d->lastTopHeight = dy;	break;    case QMainWindow::Right:	dl = d->right;	if ( d->lRight )	    dy = d->lRight->geometry().y() + ( d->top && !d->top->isEmpty() ? 8 : 0 );	if ( d->lRight && d->lastTopHeight != -1 && !dy )	    dy = d->lastTopHeight;	else	    d->lastTopHeight = dy;	break;    case QMainWindow::Top:	dl = d->top;	dy = -9;	break;    case QMainWindow::Bottom:	dl = d->bottom;	dy = -9;	break;    case QMainWindow::Unmanaged:	dl = d->unmanaged;	break;    case QMainWindow::Minimized:	dl = d->hidden;	break;    case QMainWindow::TornOff:	dl = d->tornOff;	break;    }    QList<QMainWindowPrivate::ToolBar> bars;    QMap<QRect, QList<QMainWindowPrivate::ToolBar> > rows;    QMainWindowPrivate::ToolBar *first = 0, *last = 0;    QMainWindowPrivate::ToolBar *t = dl->first();    int oldPos = dl->first() ? tb_pos( dl->first()->t, o, TRUE ) : 0;    bool makeNextNl = FALSE;    bool hadNl = FALSE;    while ( t ) {	if ( !t->t->isVisibleTo( t->t->parentWidget() ) ) {	    t = dl->next();	    continue;	}	if ( t->t == tb )	    hadNl = t->nl;	else	    last = t;	if ( !first && t->t != tb )	    first = t;	int pos = tb_pos( t->t, o, TRUE );	if ( pos != oldPos ) {	    QRect r;	    if ( o == Qt::Horizontal ) { 		r = QRect( dockArea.x(), QMAX( oldPos, dockArea.y() ), 			   dockArea.width(),			   bars.last() ? bars.last()->t->height() : pos - oldPos - dockArea.y() );	    } else {		r = QRect( QMAX( oldPos, dockArea.x() ), dockArea.y(),			   bars.last() ? bars.last()->t->width() : pos - oldPos - dockArea.x(),			   dockArea.height() );	    }	    rows[ r ] = bars;	    bars.clear();	    bars.append( t );	    if ( t->t == tb ) {		makeNextNl = TRUE;		t->nl = FALSE;	    } else {		makeNextNl = FALSE;		t->nl = TRUE;	    }	    oldPos = pos;	} else {	    if ( !makeNextNl ) {		t->nl = FALSE;	    } else {		t->nl = TRUE;	    }	    makeNextNl = FALSE;	    bars.append( t );	}	t = dl->next();    }    if ( !bars.isEmpty() ) {	    QRect r;	    if ( o == Qt::Horizontal ) {		r = QRect( dockArea.x(), bars.last()->t->y(), dockArea.width(), bars.last()->t->height() );	    } else {		r = QRect( bars.last()->t->x(), dockArea.y(), bars.last()->t->width(), dockArea.height() );	    }	    rows[ r ] = bars;	    bars.clear();    }    QMainWindowPrivate::ToolBarDock *dummy;    t = d->findToolbar( tb, dummy );    QMainWindowPrivate::ToolBar *me = t;    t->extraOffset = rect_pos( d->oldPosRect, o ) + rect_pos( dockArea, o ) - dy;    if ( rows.isEmpty() ) {	relative = 0;    } else {	QMap<QRect, QList<QMainWindowPrivate::ToolBar> >::Iterator it = rows.begin();#ifdef QMAINWINDOW_DEBUG	qDebug( "compare (%d, %d, %d, %d) ...",		d->oldPosRect.x(), d->oldPosRect.y(),		d->oldPosRect.width(), d->oldPosRect.height() );#endif	for ( ; it != rows.end(); ++it ) {#ifdef QMAINWINDOW_DEBUG	    qDebug( "  ... width (%d, %d, %d, %d)",		    it.key().x(), it.key().y(),		    it.key().width(), it.key().height() );#endif	    if ( it.key().intersects( d->oldPosRect ) ) {		QRect ir = it.key().intersect( d->oldPosRect );		if ( rect_extend( ir, o, TRUE ) < 3 )		    continue;		int div = 4;		int mul = 3;		if ( d->opaque ) {		    mul = 2;		    div = 5;		}		bool contains = it.key().contains( d->oldPosRect );		QRect oldPosRect( d->oldPosRect ); // g++ 2.7.2.3 bug		if ( !contains && rect_extend( oldPosRect, o, TRUE ) > rect_extend( it.key(), o, TRUE ) &&		     rect_pos( oldPosRect, o, TRUE ) < rect_pos( it.key(), o, TRUE ) &&		     rect_pos( oldPosRect, o, TRUE ) + rect_extend( oldPosRect, o, TRUE ) >		     rect_pos( it.key(), o, TRUE ) + rect_extend( it.key(), o, TRUE ) )		    contains = TRUE;		if ( !contains && rect_extend( ir, o, TRUE ) < ( mul * rect_extend( it.key(), o, TRUE ) ) / div ) {		    if ( rect_pos( ir, o, TRUE ) <= rect_pos( it.key(), o, TRUE ) ) {#ifdef QMAINWINDOW_DEBUG			qDebug( "above" );#endif			relative = ( *it ).first()->t;			ipos = QMainWindowPrivate::Above;			QMainWindowPrivate::ToolBar *l = ( *it ).first();			if ( relative == tb && ( *it ).next() ) {			    relative = ( *it ).current()->t;			} else if ( relative == tb ) {			    ipos = QMainWindowPrivate::SameIndex;			    l->nl = TRUE;			}		    } else {#ifdef QMAINWINDOW_DEBUG			qDebug( "below" );#endif			relative = ( *it ).first()->t;			ipos = QMainWindowPrivate::Below;			QMainWindowPrivate::ToolBar *l = ( *it ).first();			if ( relative == tb && ( *it ).next() ) {			    relative = ( *it ).current()->t;			} else if ( relative == tb ) {			    ipos = QMainWindowPrivate::SameIndex;			    l->nl = TRUE;			}		    }		} else {#ifdef QMAINWINDOW_DEBUG		    qDebug( "insinde" );#endif		    bars = *it;		    t = bars.first();		    QMainWindowPrivate::ToolBar *b = 0, *last = 0;		    bool hasMyself = FALSE;		    while ( t ) {			if ( t->t == tb ) {			    hasMyself = TRUE;			    t = bars.next();			    continue;			}			if ( tb_pos( t->t, o ) + tb_extend( t->t, o ) / 2 < rect_pos( d->oldPosRect, o ) ) {			    b = t;			    t = bars.next();			    continue;			}			last = t;			break;		    }		    if ( !b && hadNl && me )			me->nl = TRUE;		    if ( !b && last ) {			relative = last->t;			ipos = QMainWindowPrivate::Before;#ifdef QMAINWINDOW_DEBUG			qDebug( "...before" );#endif		    } else if ( b ) {			relative = b->t;			ipos = QMainWindowPrivate::After;#ifdef QMAINWINDOW_DEBUG			qDebug( "...after" );#endif		    }		    if ( !relative && hasMyself ) {#ifdef QMAINWINDOW_DEBUG			qDebug( "...no relative and have myself => self index" );#endif			relative = tb;			ipos = QMainWindowPrivate::SameIndex;		    } else if ( !relative ) {#ifdef QMAINWINDOW_DEBUG			qDebug( "AUTSCH!!!!!!!!!!" );#endif		    }		}		return;	    }	}    }    if ( rect_pos( d->oldPosRect, o, TRUE ) < rect_pos( dockArea, o, TRUE ) && first ) {	relative = first->t;	ipos = QMainWindowPrivate::Above;    } else if ( rect_pos( d->oldPosRect, o, TRUE ) + rect_extend( d->oldPosRect, o, TRUE ) >		rect_pos( dockArea, o, TRUE ) + rect_extend( d->oldPosRect, o, TRUE ) && last ) {	relative = last->t;	ipos = QMainWindowPrivate::Below;    } else {	relative = 0;	ipos = QMainWindowPrivate::Before;    }}#endif// NOT REVISED/*! \class QMainWindow qmainwindow.h  \brief The QMainWindow class provides a typical application window,  with a menu bar, some tool bars and a status bar.  \ingroup application  In addition, you need the large central widget, which you supply and  tell QMainWindow about using setCentralWidget(), and perhaps a few  tool bars, which you can add using addToolBar().  The central widget is not touched by QMainWindow.  QMainWindow  manages its geometry, and that is all.  For example, the  application/application.cpp example (an editor) sets a QMultiLineEdit  to be the central widget.  QMainWindow automatically detects the creation of a menu bar or  status bar if you specify the QMainWindow as parent, or you can use  the provided menuBar() and statusBar() functions.  menuBar() and  statusBar() create a suitable widget if one doesn't exist, and  updates the window's layout to make space.  QMainWindow also provides a QToolTipGroup connected to the status  bar.  toolTipGroup() provides access to the QToolTipGroup, but there  is no way to set the tool tip group.  The QMainWindow allows by default toolbars in all docking areas.  You can use setDockEnabled() to enable and disable docking areas  for toolbars. Currently, only \c Top, \c Left, \c Right, \c Bottom  and \c Minimized are meaningful.  Several functions let you change the appearance of a QMainWindow  globally: <ul>  <li> setRightJustification() determines whether QMainWindow  should ensure that the toolbars fill the available space  (see also QToolBar::setHorizontalStretchable() and QToolBar::setVerticalStretchable()),  <li>  setUsesBigPixmaps() determines whether QToolButton (and other  classes) should draw small or large pixmaps (see QIconSet for more  about that),  <li> setUsesTextLabel() determines whether the toolbar buttons (and  other classes), should display a textlabel in addition to pixmaps (see  QToolButton for more about that).  </ul>  Toolbars can be dragged by the user into each enabled docking area  and inside each docking area to change the order of the toolbars  there. This feature can be enabled and disabled using setToolBarsMovable().  By default this feature is enabled. If the \c Minimized dock is enabled the user  can hide(minimize)/show(restore) a toolbar with a click on the toolbar handle. The handles of  all minimized toolbars are drawn below the menu bar in one row, and if the user  moves the mouse cursor onto such a handle, the label of the toolbar  is displayed in a tool tip (see QToolBar::label()). So if you enable the Minimized dock,  you should specify a meaningful label for each toolbar.  Normally toolbars are moved transparently (this means while the user  drags one, a rectangle is drawn on the screen). With setOpaqueMoving()  it's possible to switch between opaque and transparent moving  of toolbars.  The main window's menubar is static (on the top) by default. If you want a movable  menubar, create a QMenuBar as stretchable widget inside its  own movable toolbar and restrict this toolbar to only live within the  Top or Bottom dock:  \code  QToolBar *tb = new QToolBar( this );  addToolBar( tb, tr( "Menubar" ), Top, FALSE );  QMenuBar *mb = new QMenuBar( tb );  mb->setFrameStyle( QFrame::NoFrame );  tb->setStretchableWidget( mb );  setDockEnabled( tb, Left, FALSE );  setDockEnabled( tb, Right, FALSE );  \endcode  An application with multiple toolbars can choose to save the current  toolbar layout in order to restore it in the next session. To do so,  use getLocation() on each toolbar, store the data and restore the  layout using moveToolBar() on each toolbar again. When restoring,  ensure to move the toolbars in exactly the same order in which you  got the information.  For multi-document interfaces (MDI), use a QWorkspace as central  widget.  <img src=qmainwindow-m.png> <img src=qmainwindow-w.png>  \sa QToolBar QStatusBar QMenuBar QToolTipGroup QDialog*//*!  \enum QMainWindow::ToolBarDock  Each toolbar can be in one of the following positions:  <ul>    <li>\c Top - above the central widget, below the menubar.    <li>\c Bottom - below the central widget, above the status bar.    <li>\c Left - to the left of the central widget.    <li>\c Right - to the left of the central widget.    <li>\c Minimized - the toolbar is not shown - all handles of minimized toolbars    are drawn in one row below the menu bar.  </ul>  Other values are also defined for future expansion.*//*!  Constructs an empty main window. */QMainWindow::QMainWindow( QWidget * parent, const char * name, WFlags f )    : QWidget( parent, name, f ){    d = new QMainWindowPrivate;#ifndef QT_NO_TOOLBAR    d->hideDock = new QHideDock( this, d );    d->opaque = FALSE;#endif    installEventFilter( this );}/*! Destructs the object and frees any allocated resources.*/QMainWindow::~QMainWindow(){    delete layout();    delete d;}#ifndef QT_NO_MENUBAR/*!  Sets this main window to use the menu bar \a newMenuBar.  The old menu bar, if there was any, is deleted along with its  contents.  \sa menuBar()*/void QMainWindow::setMenuBar( QMenuBar * newMenuBar ){    if ( !newMenuBar )	return;    if ( d->mb )	delete d->mb;    d->mb = newMenuBar;

⌨️ 快捷键说明

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