?? qwhatsthis.cpp
字號(hào):
}void QWhatsThisPrivate::leaveWhatsThisMode(){ if ( state == Waiting ) { QPtrDictIterator<QWhatsThisButton> it( *(wt->buttons) ); QWhatsThisButton * b; while( (b=it.current()) != 0 ) { ++it; b->setOn( FALSE ); }#ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor();#endif state = Inactive; qApp->removeEventFilter( this ); }}void QWhatsThisPrivate::say_helper(QWidget* widget,const QPoint& ppos,bool init){ const int shadowWidth = 6; // also used as '5' and '6' and even '8' below const int vMargin = 8; const int hMargin = 12; if ( currentText.isEmpty() ) return; QRect r;#ifndef QT_NO_RICHTEXT QSimpleRichText* doc = 0; if ( QStyleSheet::mightBeRichText( currentText ) ) { doc = new QSimpleRichText( currentText, whatsThat->font() ); doc->adjustSize(); if ( doc->width() > QApplication::desktop()->width() - shadowWidth - 2*hMargin ) { doc->setWidth( QApplication::desktop()->width() - shadowWidth - 2*hMargin ); } r.setRect( 0, 0, doc->width(), doc->height() ); } else#endif { int sw = QApplication::desktop()->width() / 3; if ( sw < 200 ) sw = 200; else if ( sw > 300 ) sw = 300; r = whatsThat->fontMetrics().boundingRect( 0, 0, sw, 1000, AlignLeft + AlignTop + WordBreak + ExpandTabs, currentText ); } int w = r.width() + 2*hMargin; int h = r.height() + 2*vMargin; if ( init ) { // okay, now to find a suitable location int x; // first try locating the widget immediately above/below, // with nice alignment if possible. QPoint pos; if ( widget ) pos = widget->mapToGlobal( QPoint( 0,0 ) ); if ( widget && w > widget->width() + 16 ) x = pos.x() + widget->width()/2 - w/2; else x = ppos.x() - w/2; // squeeze it in if that would result in part of what's this // being only partially visible if ( x + w > QApplication::desktop()->width() ) x = (widget? (QMIN(QApplication::desktop()->width(), pos.x() + widget->width()) ) : QApplication::desktop()->width() ) - w; int sx = QApplication::desktop()->x(); int sy = QApplication::desktop()->y(); if ( x < sx ) x = sx; int y; if ( widget && h > widget->height() + 16 ) { y = pos.y() + widget->height() + 2; // below, two pixels spacing // what's this is above or below, wherever there's most space if ( y + h + 10 > QApplication::desktop()->height() ) y = pos.y() + 2 - shadowWidth - h; // above, overlap } y = ppos.y() + 2; // squeeze it in if that would result in part of what's this // being only partially visible if ( y + h > QApplication::desktop()->height() ) y = ( widget ? (QMIN(QApplication::desktop()->height(), pos.y() + widget->height()) ) : QApplication:: desktop()->height() ) - h; if ( y < sy ) y = sy; whatsThat->setGeometry( x, y, w + shadowWidth, h + shadowWidth ); whatsThat->show(); } // now for super-clever shadow stuff. super-clever mostly in // how many window system problems it skirts around. QPainter p( whatsThat ); p.setPen( whatsThat->colorGroup().foreground() ); p.drawRect( 0, 0, w, h ); p.setPen( whatsThat->colorGroup().mid() ); p.setBrush( whatsThat->colorGroup().background() ); p.drawRect( 1, 1, w-2, h-2 ); p.setPen( whatsThat->colorGroup().foreground() );#ifndef QT_NO_RICHTEXT if ( doc ) { doc->draw( &p, hMargin, vMargin, r, whatsThat->colorGroup(), 0 ); delete doc; } else#endif { p.drawText( hMargin, vMargin, r.width(), r.height(), AlignLeft + AlignTop + WordBreak + ExpandTabs, currentText ); } p.setPen( whatsThat->colorGroup().shadow() ); p.drawPoint( w + 5, 6 ); p.drawLine( w + 3, 6, w + 5, 8 ); p.drawLine( w + 1, 6, w + 5, 10 ); int i; for( i=7; i < h; i += 2 ) p.drawLine( w, i, w + 5, i + 5 ); for( i = w - i + h; i > 6; i -= 2 ) p.drawLine( i, h, i + 5, h + 5 ); for( ; i > 0 ; i -= 2 ) p.drawLine( 6, h + 6 - i, i + 5, h + 5 );}void QWhatsThisPrivate::say( QWidget * widget, const QString &text, const QPoint& ppos){ currentText = text; // make the widget, and set it up if ( !whatsThat ) { whatsThat = new QWidget( 0, "automatic what's this? widget", WType_Popup ); whatsThat->setBackgroundMode( QWidget::NoBackground ); whatsThat->setPalette( QToolTip::palette(), TRUE ); whatsThat->installEventFilter( this ); } say_helper(widget,ppos,TRUE);}QWhatsThisPrivate::WhatsThisItem* QWhatsThisPrivate::newItem( QWidget * widget ){ WhatsThisItem * i = dict->find( (void *)widget ); if ( i ) QWhatsThis::remove( widget ); i = new WhatsThisItem; dict->insert( (void *)widget, i ); QWidget * t = widget->topLevelWidget(); if ( !tlw->find( (void *)t ) ) { tlw->insert( (void *)t, t ); t->installEventFilter( this ); } connect( widget, SIGNAL(destroyed()), this, SLOT(cleanupWidget()) ); return i;}void QWhatsThisPrivate::add( QWidget * widget, QWhatsThis* special ){ newItem( widget )->whatsthis = special;}void QWhatsThisPrivate::add( QWidget * widget, const QString &text ){ newItem( widget )->s = text;}// and finally the What's This class itself/*! Adds \a text as <i>What's This</i> help for \a widget. If the text is rich text formatted (ie. it contains markup), it will be rendered with the default stylesheet QStyleSheet::defaultSheet(). The text is destroyed if the widget is later destroyed and so need not be explicitly removed. \sa remove()*/void QWhatsThis::add( QWidget * widget, const QString &text ){ QWhatsThisPrivate::setUpWhatsThis(); wt->add(widget,text);}/*! Removes the <i>What's This</i> help for \a widget. This happens automatically if the widget is destroyed. \sa add()*/void QWhatsThis::remove( QWidget * widget ){ QWhatsThisPrivate::setUpWhatsThis(); QWhatsThisPrivate::WhatsThisItem * i = wt->dict->find( (void *)widget ); if ( !i ) return; wt->dict->take( (void *)widget ); i->deref(); if ( !i->count ) delete i;}/*! Returns the text for \a widget, or a null string if there is no <i>What's This</i> help for \a widget. \sa add()*/QString QWhatsThis::textFor( QWidget * widget, const QPoint& pos){ QWhatsThisPrivate::setUpWhatsThis(); QWhatsThisPrivate::WhatsThisItem * i = wt->dict->find( widget ); if (!i) return QString::null; return i->whatsthis? i->whatsthis->text( pos ) : i->s;}/*! Creates a QToolButton pre-configured to enter <i>What's This</i> mode when clicked. You will often use this with a toolbar: \code (void)QWhatsThis::whatsThisButton( my_help_tool_bar ); \endcode*/QToolButton * QWhatsThis::whatsThisButton( QWidget * parent ){ QWhatsThisPrivate::setUpWhatsThis(); return new QWhatsThisButton( parent, "automatic what's this? button" );}/*! \base64 whatsthis.pngiVBORw0KGgoAAAANSUhEUgAAARwAAAD2CAM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rzYeCveSIkiX1X6ncxc+tUTeW6pzQJEebV2kY1BGsJ4dqI0YxzwU5dusctXrWx9DW5bhT5xQWK1v9JNvJUVordZ44u2CrT4Q9ZAAcWwFgcgAwOQCYHABMDgAmBwCTA4DJAagpOd5SR3J8pYbkJIra95hIJ9HJ9HAb3xF6dDY57bcziT26sk/WdTuYHEwOJqfdbmwl57V6HjXIaR+j6X+6RzkopxCUA4ByAFAOAMoBQDkAKAcA5QCgHACUA4ByAP4PEPjyFx6Cy2AAAAAASUVORK5CYII=*//*! Constructs a dynamic <i>What's This</i> object for \a widget. When the widget is queried by the user, the text() function of this QWhatsThis will be called to provide the appropriate text, rather than using text assigned by add().*/QWhatsThis::QWhatsThis( QWidget * widget){ QWhatsThisPrivate::setUpWhatsThis(); wt->add(widget,this);}/*! Destructs the object and frees any allocated resources.*/QWhatsThis::~QWhatsThis(){}/*! This virtual functions returns the text for position \e p in the widget that this <i>What's This</i> object documents. If there is no <i>What's This</i> text for a position, QString::null is returned. The default implementation returns QString::null.*/QString QWhatsThis::text( const QPoint & ){ return QString::null;}/*! Enters <i>What's This</i>? mode and returns immediately. Qt will install a special cursor and take over mouse input until the user clicks somewhere, then show any help available and switch out of <i>What's This</i> mode. Finally, Qt removes the special cursor and help window then restores ordinary event processing, at which point the left mouse button is not pressed. The user can also use the Escape key to leave <i>What's This</i>? mode.\sa inWhatsThisMode(), leaveWhatsThisMode()*/void QWhatsThis::enterWhatsThisMode(){ QWhatsThisPrivate::setUpWhatsThis(); if ( wt->state == QWhatsThisPrivate::Inactive ) {#ifndef QT_NO_CURSOR QApplication::setOverrideCursor( *wt->cursor, FALSE );#endif wt->state = QWhatsThisPrivate::Waiting; qApp->installEventFilter( wt ); }}/*! Returns whether the application is in <i>What's This</i> mode. \sa enterWhatsThisMode(), leaveWhatsThisMode() */bool QWhatsThis::inWhatsThisMode(){ if (!wt) return FALSE; return wt->state == QWhatsThisPrivate::Waiting;}/*! Leaves <i>What's This</i>? question mode This function is used internally by widgets that support QWidget::customWhatsThis(), applications do not usually call it. An example for such a kind of widget is QPopupMenu: Menus still work normally in <i>What's This</i> mode, but provide help texts for single menu items instead. If \e text is not a null string, then a <i>What's This</i> help window is displayed at the global screen position \e pos.\sa inWhatsThisMode(), enterWhatsThisMode()*/void QWhatsThis::leaveWhatsThisMode( const QString& text, const QPoint& pos ){ if ( !inWhatsThisMode() ) return; wt->leaveWhatsThisMode(); if ( !text.isNull() ) wt->say( 0, text, pos );}#include "qwhatsthis.moc"#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -