Q3TitleBar Class Reference

#include <q3titlebar_p.h>

Inheritance diagram for Q3TitleBar:

Inheritance graph
[legend]
Collaboration diagram for Q3TitleBar:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 47 of file q3titlebar_p.h.

Public Slots

void setActive (bool)

Signals

void doActivate ()
void doNormal ()
void doClose ()
void doMaximize ()
void doMinimize ()
void doShade ()
void showOperationMenu ()
void popupOperationMenu (const QPoint &)
void doubleClicked ()

Public Member Functions

 Q3TitleBar (QWidget *w, QWidget *parent, Qt::WindowFlags f=0)
 ~Q3TitleBar ()
bool isActive () const
bool usesActiveColor () const
bool isMovable () const
void setMovable (bool)
bool autoRaise () const
void setAutoRaise (bool)
QWidgetwindow () const
bool isTool () const
QSize sizeHint () const
QStyleOptionTitleBar getStyleOption () const

Protected Member Functions

bool event (QEvent *)
void resizeEvent (QResizeEvent *)
void contextMenuEvent (QContextMenuEvent *)
void changeEvent (QEvent *)
void mousePressEvent (QMouseEvent *)
void mouseDoubleClickEvent (QMouseEvent *)
void mouseReleaseEvent (QMouseEvent *)
void mouseMoveEvent (QMouseEvent *)
void enterEvent (QEvent *e)
void leaveEvent (QEvent *e)
void paintEvent (QPaintEvent *p)
virtual void cutText ()


Constructor & Destructor Documentation

Q3TitleBar::Q3TitleBar ( QWidget w,
QWidget parent,
Qt::WindowFlags  f = 0 
)

Definition at line 98 of file q3titlebar.cpp.

References d, QSizePolicy::Expanding, QSizePolicy::Fixed, QStyle::SC_None, setAutoRaise(), QWidget::setMouseTracking(), QWidget::setSizePolicy(), QWidget::setWindowTitle(), QStyle::SH_TitleBar_AutoRaise, QWidget::style(), styleHint(), w, and Qt::WindowMaximizeButtonHint.

00099     : QWidget(*new Q3TitleBarPrivate, parent, Qt::WStyle_Customize | Qt::WStyle_NoBorder)
00100 {
00101     Q_D(Q3TitleBar);
00102     if (f == 0 && w)
00103         f = w->windowFlags();
00104     d->flags = f;
00105     d->window = w;
00106     d->buttonDown = QStyle::SC_None;
00107     d->act = 0;
00108     if (w) {
00109         if (w->minimumSize() == w->maximumSize())
00110             d->flags &= ~Qt::WindowMaximizeButtonHint;
00111         setWindowTitle(w->windowTitle());
00112     }
00113 
00114     d->readColors();
00115     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
00116     setMouseTracking(true);
00117     setAutoRaise(style()->styleHint(QStyle::SH_TitleBar_AutoRaise, 0, this));
00118 }

Here is the call graph for this function:

Q3TitleBar::~Q3TitleBar (  ) 

Definition at line 120 of file q3titlebar.cpp.

00121 {
00122 }


Member Function Documentation

bool Q3TitleBar::isActive (  )  const

Definition at line 534 of file q3titlebar.cpp.

Referenced by Q3DockWindow::drawContents(), Q3DockWindow::drawFrame(), and usesActiveColor().

00535 {
00536     return d_func()->act;
00537 }

bool Q3TitleBar::usesActiveColor (  )  const

Definition at line 539 of file q3titlebar.cpp.

References isActive(), QWidget::isActiveWindow(), QWidget::window(), and window().

Referenced by paintEvent().

00540 {
00541     return (isActive() && isActiveWindow()) ||
00542         (!window() && QWidget::window()->isActiveWindow());
00543 }

Here is the call graph for this function:

bool Q3TitleBar::isMovable (  )  const

Definition at line 581 of file q3titlebar.cpp.

00582 {
00583     return d_func()->movable;
00584 }

void Q3TitleBar::setMovable ( bool   ) 

Definition at line 576 of file q3titlebar.cpp.

00577 {
00578     d_func()->movable = b;
00579 }

bool Q3TitleBar::autoRaise (  )  const

Definition at line 591 of file q3titlebar.cpp.

Referenced by enterEvent(), leaveEvent(), mouseMoveEvent(), and paintEvent().

00592 {
00593     return d_func()->autoraise;
00594 }

void Q3TitleBar::setAutoRaise ( bool   ) 

Definition at line 586 of file q3titlebar.cpp.

Referenced by Q3TitleBar().

00587 {
00588     d_func()->autoraise = b;
00589 }

QWidget * Q3TitleBar::window (  )  const

Returns the window for this widget, i.e. the next ancestor widget that has (or could have) a window-system frame.

If the widget is a window, the widget itself is returned.

Typical usage is changing the window title:

        aWidget->window()->setWindowTitle("New Window Title");

See also:
isWindow()

Reimplemented from QWidget.

Definition at line 545 of file q3titlebar.cpp.

References QWidget::window().

Referenced by Q3AccessibleTitleBar::doAction(), Q3DockWindowTitleBar::mousePressEvent(), Q3AccessibleTitleBar::text(), and usesActiveColor().

00546 {
00547     return d_func()->window;
00548 }

Here is the call graph for this function:

bool Q3TitleBar::isTool (  )  const

Definition at line 415 of file q3titlebar.cpp.

References flags, Qt::Tool, and Qt::WindowType_Mask.

00416 {
00417     return (d_func()->flags & Qt::WindowType_Mask) == Qt::Tool;
00418 }

QSize Q3TitleBar::sizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 596 of file q3titlebar.cpp.

References QStyle::CC_TitleBar, QWidget::ensurePolished(), QStyle::pixelMetric(), QStyle::PM_TitleBarHeight, QStyle::SC_TitleBarSysMenu, QWidget::style(), QStyle::subControlRect(), and QRect::width().

00597 {
00598     ensurePolished();
00599     QStyleOptionTitleBar opt = d_func()->getStyleOption();
00600     QRect menur = style()->subControlRect(QStyle::CC_TitleBar, &opt,
00601                                           QStyle::SC_TitleBarSysMenu, this);
00602     return QSize(menur.width(), style()->pixelMetric(QStyle::PM_TitleBarHeight, &opt, this));
00603 }

Here is the call graph for this function:

QStyleOptionTitleBar Q3TitleBar::getStyleOption (  )  const

Definition at line 124 of file q3titlebar.cpp.

Referenced by Q3DockWindowTitleBar::Q3DockWindowTitleBar().

00125 {
00126     return d_func()->getStyleOption();
00127 }

void Q3TitleBar::setActive ( bool   )  [slot]

Definition at line 524 of file q3titlebar.cpp.

References d, and QWidget::update().

Referenced by event().

00525 {
00526     Q_D(Q3TitleBar);
00527     if (d->act == active)
00528         return ;
00529 
00530     d->act = active;
00531     update();
00532 }

void Q3TitleBar::doActivate (  )  [signal]

Referenced by mousePressEvent().

void Q3TitleBar::doNormal (  )  [signal]

Referenced by mouseReleaseEvent().

void Q3TitleBar::doClose (  )  [signal]

Referenced by mouseDoubleClickEvent(), mousePressEvent(), mouseReleaseEvent(), and Q3DockWindowTitleBar::Q3DockWindowTitleBar().

void Q3TitleBar::doMaximize (  )  [signal]

Referenced by mouseReleaseEvent().

void Q3TitleBar::doMinimize (  )  [signal]

Referenced by mouseReleaseEvent().

void Q3TitleBar::doShade (  )  [signal]

Referenced by mouseReleaseEvent().

void Q3TitleBar::showOperationMenu (  )  [signal]

Referenced by mousePressEvent().

void Q3TitleBar::popupOperationMenu ( const QPoint  )  [signal]

Referenced by contextMenuEvent().

void Q3TitleBar::doubleClicked (  )  [signal]

Referenced by Q3DockWindowTitleBar::mouseDoubleClickEvent(), and mouseDoubleClickEvent().

bool Q3TitleBar::event ( QEvent e  )  [protected, virtual]

This is the main event handler; it handles event event. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

Key press and release events are treated differently from other events. event() checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event() calls keyPressEvent().

Mouse and tablet event handling is also slightly special: only when the widget is enabled, event() will call the specialized handlers such as mousePressEvent(); otherwise it will discard the event.

This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.

See also:
closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), keyPressEvent(), keyReleaseEvent(), leaveEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), QObject::event(), QObject::timerEvent()

Reimplemented from QWidget.

Definition at line 550 of file q3titlebar.cpp.

References QEvent::ApplicationPaletteChange, cutText(), d, QWidget::event(), setActive(), QEvent::type(), QWidget::update(), QEvent::WindowActivate, QEvent::WindowDeactivate, QEvent::WindowIconChange, and QEvent::WindowTitleChange.

00551 {
00552     Q_D(Q3TitleBar);
00553     if (d->inevent)
00554         return QWidget::event(e);
00555     d->inevent = true;
00556     if (e->type() == QEvent::ApplicationPaletteChange) {
00557         d->readColors();
00558         return true;
00559     } else if (e->type() == QEvent::WindowActivate) {
00560         setActive(d->act);
00561     } else if (e->type() == QEvent::WindowDeactivate) {
00562         bool wasActive = d->act;
00563         setActive(false);
00564         d->act = wasActive;
00565     } else if (e->type() == QEvent::WindowIconChange) {
00566         update();
00567     } else if (e->type() == QEvent::WindowTitleChange) {
00568         cutText();
00569         update();
00570     }
00571 
00572     d->inevent = false;
00573     return QWidget::event(e);
00574 }

Here is the call graph for this function:

void Q3TitleBar::resizeEvent ( QResizeEvent r  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().

The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.

See also:
moveEvent(), event(), resize(), QResizeEvent, paintEvent(), {Scribble Example}

Reimplemented from QWidget.

Definition at line 409 of file q3titlebar.cpp.

References cutText(), and QWidget::resizeEvent().

Referenced by Q3DockWindowTitleBar::resizeEvent().

00410 {
00411     QWidget::resizeEvent(r);
00412     cutText();
00413 }

Here is the call graph for this function:

void Q3TitleBar::contextMenuEvent ( QContextMenuEvent e  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive widget context menu events.

The handler is called when the widget's contextMenuPolicy is Qt::DefaultContextMenu.

The default implementation ignores the context event. See the QContextMenuEvent documentation for more details.

See also:
event(), QContextMenuEvent customContextMenuRequested()

Reimplemented from QWidget.

Definition at line 270 of file q3titlebar.cpp.

References QEvent::accept(), QStyle::CC_TitleBar, d, emit, QContextMenuEvent::globalPos(), QStyle::hitTestComplexControl(), QEvent::ignore(), popupOperationMenu(), QContextMenuEvent::pos(), QStyle::SC_TitleBarLabel, QStyle::SC_TitleBarSysMenu, and QWidget::style().

00271 {
00272     Q_D(Q3TitleBar);
00273     QStyleOptionTitleBar opt = d->getStyleOption();
00274     QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(),
00275                                                              this);
00276     if(ctrl == QStyle::SC_TitleBarLabel || ctrl == QStyle::SC_TitleBarSysMenu) {
00277         e->accept();
00278         emit popupOperationMenu(e->globalPos());
00279     } else {
00280         e->ignore();
00281     }
00282 }

Here is the call graph for this function:

void Q3TitleBar::changeEvent ( QEvent ev  )  [protected, virtual]

This event handler can be reimplemented to handle state changes.

The state being changed in this event can be retrieved through event event.

Change events include: QEvent::ToolBarChange, QEvent::ActivationChange, QEvent::EnabledChange, QEvent::FontChange, QEvent::StyleChange, QEvent::PaletteChange, QEvent::WindowTitleChange, QEvent::IconTextChange, QEcvent::ModifiedChange, QEvent::MouseTrackingChange, QEvent::ParentChange, QEvent::WindowStateChange, QEvent::LanguageChange, QEvent::LocaleChange, QEvent::LayoutDirectionChange.

Reimplemented from QWidget.

Definition at line 193 of file q3titlebar.cpp.

References QWidget::changeEvent(), QEvent::ModifiedChange, QEvent::type(), and QWidget::update().

00194 {
00195     if(ev->type() == QEvent::ModifiedChange)
00196         update();
00197     QWidget::changeEvent(ev);
00198 }

Here is the call graph for this function:

void Q3TitleBar::mousePressEvent ( QMouseEvent e  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

See also:
mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 200 of file q3titlebar.cpp.

References QMouseEvent::button(), QStyle::CC_TitleBar, d, doActivate(), doClose(), QApplication::doubleClickInterval(), emit, QStyle::hitTestComplexControl(), Qt::LeftButton, QWidget::mapToParent(), QMouseEvent::pos(), QWidget::repaint(), QStyle::SC_None, QStyle::SC_TitleBarCloseButton, QStyle::SC_TitleBarLabel, QStyle::SC_TitleBarMaxButton, QStyle::SC_TitleBarMinButton, QStyle::SC_TitleBarNormalButton, QStyle::SC_TitleBarShadeButton, QStyle::SC_TitleBarSysMenu, QStyle::SC_TitleBarUnshadeButton, showOperationMenu(), QWidget::style(), t, Qt::WindowMaximizeButtonHint, Qt::WindowMinimizeButtonHint, Qt::WindowMinMaxButtonsHint, Qt::WindowShadeButtonHint, and Qt::WindowSystemMenuHint.

Referenced by Q3DockWindowTitleBar::mousePressEvent().

00201 {
00202     Q_D(Q3TitleBar);
00203     if (!d->act)
00204         emit doActivate();
00205     if (e->button() == Qt::LeftButton) {
00206         d->pressed = true;
00207         QStyleOptionTitleBar opt = d->getStyleOption();
00208         QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,
00209                                                                  e->pos(), this);
00210         switch (ctrl) {
00211         case QStyle::SC_TitleBarSysMenu:
00212             if (d->flags & Qt::WindowSystemMenuHint) {
00213                 d->buttonDown = QStyle::SC_None;
00214                 static QTime *t = 0;
00215                 static Q3TitleBar *tc = 0;
00216                 if (!t)
00217                     t = new QTime;
00218                 if (tc != this || t->elapsed() > QApplication::doubleClickInterval()) {
00219                     emit showOperationMenu();
00220                     t->start();
00221                     tc = this;
00222                 } else {
00223                     tc = 0;
00224                     emit doClose();
00225                     return;
00226                 }
00227             }
00228             break;
00229 
00230         case QStyle::SC_TitleBarShadeButton:
00231         case QStyle::SC_TitleBarUnshadeButton:
00232             if (d->flags & Qt::WindowShadeButtonHint)
00233                 d->buttonDown = ctrl;
00234             break;
00235 
00236         case QStyle::SC_TitleBarNormalButton:
00237             if (d->flags & Qt::WindowMinMaxButtonsHint)
00238                 d->buttonDown = ctrl;
00239             break;
00240 
00241         case QStyle::SC_TitleBarMinButton:
00242             if (d->flags & Qt::WindowMinimizeButtonHint)
00243                 d->buttonDown = ctrl;
00244             break;
00245 
00246         case QStyle::SC_TitleBarMaxButton:
00247             if (d->flags & Qt::WindowMaximizeButtonHint)
00248                 d->buttonDown = ctrl;
00249             break;
00250 
00251         case QStyle::SC_TitleBarCloseButton:
00252             if (d->flags & Qt::WindowSystemMenuHint)
00253                 d->buttonDown = ctrl;
00254             break;
00255 
00256         case QStyle::SC_TitleBarLabel:
00257             d->buttonDown = ctrl;
00258             d->moveOffset = mapToParent(e->pos());
00259             break;
00260 
00261         default:
00262             break;
00263         }
00264         repaint();
00265     } else {
00266         d->pressed = false;
00267     }
00268 }

Here is the call graph for this function:

void Q3TitleBar::mouseDoubleClickEvent ( QMouseEvent e  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget.

The default implementation generates a normal mouse press event.

Note that the widgets gets a mousePressEvent() and a mouseReleaseEvent() before the mouseDoubleClickEvent().

See also:
mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(), event(), QMouseEvent

Reimplemented from QWidget.

Definition at line 457 of file q3titlebar.cpp.

References QEvent::accept(), QMouseEvent::button(), QStyle::CC_TitleBar, d, doClose(), doubleClicked(), emit, QEvent::ignore(), Qt::LeftButton, QMouseEvent::pos(), QStyle::SC_TitleBarLabel, QStyle::SC_TitleBarSysMenu, and QWidget::style().

00458 {
00459     Q_D(Q3TitleBar);
00460     if (e->button() != Qt::LeftButton) {
00461         e->ignore();
00462         return;
00463     }
00464     e->accept();
00465     QStyleOptionTitleBar opt = d->getStyleOption();
00466     switch (style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(), this)) {
00467     case QStyle::SC_TitleBarLabel:
00468         emit doubleClicked();
00469         break;
00470 
00471     case QStyle::SC_TitleBarSysMenu:
00472         if (d->flags & Qt::WStyle_SysMenu)
00473             emit doClose();
00474         break;
00475 
00476     default:
00477         break;
00478     }
00479 }

Here is the call graph for this function:

void Q3TitleBar::mouseReleaseEvent ( QMouseEvent e  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse release events for the widget.

See also:
mousePressEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 284 of file q3titlebar.cpp.

References QEvent::accept(), QMouseEvent::button(), QStyle::CC_TitleBar, d, doClose(), doMaximize(), doMinimize(), doNormal(), doShade(), emit, QStyle::hitTestComplexControl(), QEvent::ignore(), Qt::LeftButton, QMouseEvent::pos(), QWidget::repaint(), QStyle::SC_None, QStyle::SC_TitleBarCloseButton, QStyle::SC_TitleBarMaxButton, QStyle::SC_TitleBarMinButton, QStyle::SC_TitleBarNormalButton, QStyle::SC_TitleBarShadeButton, QStyle::SC_TitleBarUnshadeButton, QWidget::style(), Qt::WindowMaximizeButtonHint, Qt::WindowMinimizeButtonHint, Qt::WindowShadeButtonHint, and Qt::WindowSystemMenuHint.

Referenced by Q3DockWindowTitleBar::mouseReleaseEvent().

00285 {
00286     Q_D(Q3TitleBar);
00287     if (e->button() == Qt::LeftButton && d->pressed) {
00288         e->accept();
00289         QStyleOptionTitleBar opt = d->getStyleOption();
00290         QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,
00291                                                                  e->pos(), this);
00292         d->pressed = false;
00293         if (ctrl == d->buttonDown) {
00294             d->buttonDown = QStyle::SC_None;
00295             repaint();
00296             switch(ctrl) {
00297             case QStyle::SC_TitleBarShadeButton:
00298             case QStyle::SC_TitleBarUnshadeButton:
00299                 if(d->flags & Qt::WindowShadeButtonHint)
00300                     emit doShade();
00301                 break;
00302 
00303             case QStyle::SC_TitleBarNormalButton:
00304                 if(d->flags & Qt::WindowMaximizeButtonHint)
00305                     emit doNormal();
00306                 break;
00307 
00308             case QStyle::SC_TitleBarMinButton:
00309                 if(d->flags & Qt::WindowMinimizeButtonHint) {
00310                     if (d->window && d->window->isMinimized())
00311                         emit doNormal();
00312                     else
00313                         emit doMinimize();
00314                 }
00315                 break;
00316 
00317             case QStyle::SC_TitleBarMaxButton:
00318                 if(d->flags & Qt::WindowMaximizeButtonHint) {
00319                     if(d->window && d->window->isMaximized())
00320                         emit doNormal();
00321                     else
00322                         emit doMaximize();
00323                 }
00324                 break;
00325 
00326             case QStyle::SC_TitleBarCloseButton:
00327                 if(d->flags & Qt::WindowSystemMenuHint) {
00328                     d->buttonDown = QStyle::SC_None;
00329                     repaint();
00330                     emit doClose();
00331                     return;
00332                 }
00333                 break;
00334 
00335             default:
00336                 break;
00337             }
00338         }
00339     } else {
00340         e->ignore();
00341     }
00342 }

Here is the call graph for this function:

void Q3TitleBar::mouseMoveEvent ( QMouseEvent e  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.

See also:
setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 344 of file q3titlebar.cpp.

References QEvent::accept(), autoRaise(), QStyle::CC_TitleBar, d, QMouseEvent::globalPos(), QStyle::hitTestComplexControl(), QObject::inherits(), QWidget::isMaximized(), QWidget::mapFromGlobal(), QWidget::mapToParent(), QWidget::move(), p, QObject::parent(), QWidget::parentWidget(), QMouseEvent::pos(), QWidget::repaint(), QStyle::SC_None, QStyle::SC_TitleBarCloseButton, QStyle::SC_TitleBarLabel, QStyle::SC_TitleBarMaxButton, QStyle::SC_TitleBarMinButton, QStyle::SC_TitleBarNormalButton, QStyle::SC_TitleBarShadeButton, QStyle::SC_TitleBarSysMenu, QStyle::SC_TitleBarUnshadeButton, and QWidget::style().

Referenced by Q3DockWindowTitleBar::mouseMoveEvent().

00345 {
00346     Q_D(Q3TitleBar);
00347     e->accept();
00348     switch (d->buttonDown) {
00349     case QStyle::SC_None:
00350         if(autoRaise())
00351             repaint();
00352         break;
00353     case QStyle::SC_TitleBarSysMenu:
00354         break;
00355     case QStyle::SC_TitleBarShadeButton:
00356     case QStyle::SC_TitleBarUnshadeButton:
00357     case QStyle::SC_TitleBarNormalButton:
00358     case QStyle::SC_TitleBarMinButton:
00359     case QStyle::SC_TitleBarMaxButton:
00360     case QStyle::SC_TitleBarCloseButton:
00361         {
00362             QStyle::SubControl last_ctrl = d->buttonDown;
00363             QStyleOptionTitleBar opt = d->getStyleOption();
00364             d->buttonDown = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(), this);
00365             if (d->buttonDown != last_ctrl)
00366                 d->buttonDown = QStyle::SC_None;
00367             repaint();
00368             d->buttonDown = last_ctrl;
00369         }
00370         break;
00371 
00372     case QStyle::SC_TitleBarLabel:
00373         if (d->buttonDown == QStyle::SC_TitleBarLabel && d->movable && d->pressed) {
00374             if ((d->moveOffset - mapToParent(e->pos())).manhattanLength() >= 4) {
00375                 QPoint p = mapFromGlobal(e->globalPos());
00376 
00377                 QWidget *parent = d->window ? d->window->parentWidget() : 0;
00378                 if(parent && parent->inherits("Q3WorkspaceChild")) {
00379                     QWidget *workspace = parent->parentWidget();
00380                     p = workspace->mapFromGlobal(e->globalPos());
00381                     if (!workspace->rect().contains(p)) {
00382                         if (p.x() < 0)
00383                             p.rx() = 0;
00384                         if (p.y() < 0)
00385                             p.ry() = 0;
00386                         if (p.x() > workspace->width())
00387                             p.rx() = workspace->width();
00388                         if (p.y() > workspace->height())
00389                             p.ry() = workspace->height();
00390                     }
00391                 }
00392 
00393                 QPoint pp = p - d->moveOffset;
00394                 if (!parentWidget()->isMaximized())
00395                     parentWidget()->move(pp);
00396             }
00397         } else {
00398             QStyle::SubControl last_ctrl = d->buttonDown;
00399             d->buttonDown = QStyle::SC_None;
00400             if(d->buttonDown != last_ctrl)
00401                 repaint();
00402         }
00403         break;
00404     default:
00405         break;
00406     }
00407 }

Here is the call graph for this function:

void Q3TitleBar::enterEvent ( QEvent e  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter.

An event is sent to the widget when the mouse cursor enters the widget.

See also:
leaveEvent(), mouseMoveEvent(), event()

Reimplemented from QWidget.

Definition at line 516 of file q3titlebar.cpp.

References autoRaise(), QEvent::Leave, QWidget::parentWidget(), QWidget::repaint(), and QCoreApplication::sendEvent().

00517 {
00518     if(autoRaise() && !d_func()->pressed)
00519         repaint();
00520     QEvent e(QEvent::Leave);
00521     QApplication::sendEvent(parentWidget(), &e);
00522 }

Here is the call graph for this function:

void Q3TitleBar::leaveEvent ( QEvent e  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter.

A leave event is sent to the widget when the mouse cursor leaves the widget.

See also:
enterEvent(), mouseMoveEvent(), event()

Reimplemented from QWidget.

Definition at line 510 of file q3titlebar.cpp.

References autoRaise(), and QWidget::repaint().

00511 {
00512     if(autoRaise() && !d_func()->pressed)
00513         repaint();
00514 }

Here is the call graph for this function:

void Q3TitleBar::paintEvent ( QPaintEvent p  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.

The background can be set using setBackgroundRole() and setPalette().

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.

Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:

See also:
event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, {Analog Clock Example}

Reimplemented from QWidget.

Definition at line 420 of file q3titlebar.cpp.

References QPalette::Active, QStyleOptionComplex::activeSubControls, autoRaise(), QStyle::CC_TitleBar, d, QStyle::drawComplexControl(), QStyle::hitTestComplexControl(), QPalette::Inactive, QWidget::mapFromGlobal(), p, QStyleOption::palette, QCursor::pos(), QStyle::SC_None, QStyle::SC_TitleBarCloseButton, QStyle::SC_TitleBarLabel, QStyle::SC_TitleBarMaxButton, QStyle::SC_TitleBarMinButton, QStyle::SC_TitleBarNormalButton, QStyle::SC_TitleBarShadeButton, QStyle::SC_TitleBarSysMenu, QStyle::SC_TitleBarUnshadeButton, QPalette::setCurrentColorGroup(), QStyleOption::state, QStyle::State_MouseOver, QWidget::style(), QStyleOptionComplex::subControls, QWidget::underMouse(), usesActiveColor(), Qt::WindowMaximizeButtonHint, Qt::WindowMinMaxButtonsHint, Qt::WindowShadeButtonHint, and Qt::WindowSystemMenuHint.

00421 {
00422     Q_D(Q3TitleBar);
00423     QStyleOptionTitleBar opt = d->getStyleOption();
00424     opt.subControls = QStyle::SC_TitleBarLabel;
00425     opt.activeSubControls = d->buttonDown;
00426     if (d->flags & Qt::WindowSystemMenuHint) {
00427         opt.subControls |= QStyle::SC_TitleBarSysMenu | QStyle::SC_TitleBarCloseButton;
00428         if (d->window && (d->flags & Qt::WindowShadeButtonHint)) {
00429             if (d->window->isMinimized())
00430                 opt.subControls |= QStyle::SC_TitleBarUnshadeButton;
00431             else
00432                 opt.subControls |= QStyle::SC_TitleBarShadeButton;
00433         }
00434         if (d->window && (d->flags & Qt::WindowMinMaxButtonsHint)) {
00435             if(d->window && d->window->isMinimized())
00436                 opt.subControls |= QStyle::SC_TitleBarNormalButton;
00437             else
00438                 opt.subControls |= QStyle::SC_TitleBarMinButton;
00439         }
00440         if (d->window && (d->flags & Qt::WindowMaximizeButtonHint) && !d->window->isMaximized())
00441             opt.subControls |= QStyle::SC_TitleBarMaxButton;
00442     }
00443 
00444     QStyle::SubControl under_mouse = QStyle::SC_None;
00445     if(autoRaise() && underMouse()) {
00446         under_mouse = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,
00447                                                      mapFromGlobal(QCursor::pos()), this);
00448         opt.activeSubControls |= under_mouse;
00449         opt.state |= QStyle::State_MouseOver;
00450     }
00451     opt.palette.setCurrentColorGroup(usesActiveColor() ? QPalette::Active : QPalette::Inactive);
00452 
00453     QPainter p(this);
00454     style()->drawComplexControl(QStyle::CC_TitleBar, &opt, &p, this);
00455 }

Here is the call graph for this function:

void Q3TitleBar::cutText (  )  [protected, virtual]

Definition at line 481 of file q3titlebar.cpp.

References QStyle::CC_TitleBar, d, QWidget::font(), i, QString::left(), QString::length(), QStyle::SC_TitleBarLabel, QWidget::setWindowTitle(), QStyle::SH_TitleBar_ModifyNotification, QWidget::style(), styleHint(), QStyle::subControlRect(), QRect::width(), and QFontMetrics::width().

Referenced by event(), and resizeEvent().

00482 {
00483     Q_D(Q3TitleBar);
00484     QFontMetrics fm(font());
00485     QStyleOptionTitleBar opt = d->getStyleOption();
00486     int maxw = style()->subControlRect(QStyle::CC_TitleBar, &opt, QStyle::SC_TitleBarLabel,
00487                                        this).width();
00488     if (!d->window)
00489         return;
00490 
00491     QString txt = d->window->windowTitle();
00492     if (style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, this) && d->window
00493         && d->window->isWindowModified())
00494         txt += " *";
00495 
00496     QString cuttext = txt;
00497     if (fm.width(txt + "m") > maxw) {
00498         int i = txt.length();
00499         int dotlength = fm.width("...");
00500         while (i>0 && fm.width(txt.left(i)) + dotlength > maxw)
00501             i--;
00502         if(i != (int)txt.length())
00503             cuttext = txt.left(i) + "...";
00504     }
00505 
00506     setWindowTitle(cuttext);
00507 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:35:11 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1