Q3DockArea Class Reference

#include <q3dockarea.h>

Inheritance diagram for Q3DockArea:

Inheritance graph
[legend]
Collaboration diagram for Q3DockArea:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3DockArea class manages and lays out Q3DockWindows.

A Q3DockArea is a container which manages a list of {Q3DockWindow}s which it lays out within its area. In cooperation with the {Q3DockWindow}s it is responsible for the docking and undocking of {Q3DockWindow}s and moving them inside the dock area. Q3DockAreas also handle the wrapping of {Q3DockWindow}s to fill the available space as compactly as possible. Q3DockAreas can contain Q3ToolBars since Q3ToolBar is a Q3DockWindow subclass.

QMainWindow contains four Q3DockAreas which you can use for your Q3ToolBars and Q3DockWindows, so in most situations you do not need to use the Q3DockArea class directly. Although QMainWindow contains support for its own dock areas it isn't convenient for adding new Q3DockAreas. If you need to create your own dock areas we suggest that you create a subclass of QWidget and add your Q3DockAreas to your subclass.

qmainwindow-qdockareas.png QMainWindow's Q3DockAreas

lines Lines. Q3DockArea uses the concept of lines. A line is a horizontal region which may contain dock windows side-by-side. A dock area may have room for more than one line. When dock windows are docked into a dock area they are usually added at the right hand side of the top-most line that has room (unless manually placed by the user). When users move dock windows they may leave empty lines or gaps in non-empty lines. Qt::Dock windows can be lined up to minimize wasted space using the lineUp() function.

The Q3DockArea class maintains a position list of all its child dock windows. Qt::Dock windows are added to a dock area from position 0 onwards. Qt::Dock windows are laid out sequentially in position order from left to right, and in the case of multiple lines of dock windows, from top to bottom. If a dock window is floated it still retains its position since this is where the window will return if the user double clicks its caption. A dock window's position can be determined with hasDockWindow(). The position can be changed with moveDockWindow().

To dock or undock a dock window use Q3DockWindow::dock() and Q3DockWindow::undock() respectively. If you want to control which dock windows can dock in a dock area use setAcceptDockWindow(). To see if a dock area contains a particular dock window use {hasDockWindow()}; to see how many dock windows a dock area contains use count().

The streaming operators can write the positions of the dock windows in the dock area to a QTextStream. The positions can be read back later to restore the saved positions.

Save the positions to a QTextStream:

    ts << *myDockArea;

Restore the positions from a QTextStream:

    ts >> *myDockArea;

Definition at line 97 of file q3dockarea.h.

Public Types

enum  HandlePosition

Public Slots

void lineUp (bool keepNewLines)

Public Member Functions

 Q3DockArea (Qt::Orientation o, HandlePosition h=Normal, QWidget *parent=0, const char *name=0)
 ~Q3DockArea ()
void moveDockWindow (Q3DockWindow *w, const QPoint &globalPos, const QRect &rect, bool swap)
void removeDockWindow (Q3DockWindow *w, bool makeFloating, bool swap, bool fixNewLines=true)
void moveDockWindow (Q3DockWindow *w, int index=-1)
bool hasDockWindow (Q3DockWindow *w, int *index=0)
void invalidNextOffset (Q3DockWindow *dw)
Qt::Orientation orientation () const
HandlePosition handlePosition () const
bool eventFilter (QObject *, QEvent *)
bool isEmpty () const
int count () const
QList< Q3DockWindow * > dockWindowList () const
bool isDockWindowAccepted (Q3DockWindow *dw)
void setAcceptDockWindow (Q3DockWindow *dw, bool accept)

Private Member Functions

int findDockWindow (Q3DockWindow *w)
int lineOf (int index)
DockWindowDatadockWindowData (Q3DockWindow *w)
void dockWindow (Q3DockWindow *dockWindow, DockWindowData *data)
void updateLayout ()
void invalidateFixedSizes ()
int maxSpace (int hint, Q3DockWindow *dw)
void setFixedExtent (int d, Q3DockWindow *dw)
bool isLastDockWindow (Q3DockWindow *dw)

Private Attributes

Qt::Orientation orient
QList< Q3DockWindow * > dockWindows
Q3DockAreaLayoutlayout
HandlePosition hPos
QList< Q3DockWindow * > forbiddenWidgets
Q3DockAreaPrivate * d

Friends

class Q3DockWindow
class Q3DockWindowResizeHandle
class Q3DockAreaLayout

Related Functions

(Note that these are not member functions.)

QTextStreamoperator<< (QTextStream &ts, const Q3DockArea &dockArea)
QTextStreamoperator>> (QTextStream &ts, Q3DockArea &dockArea)

Classes

struct  DockWindowData


Member Enumeration Documentation

enum Q3DockArea::HandlePosition

A dock window has two kinds of handles, the dock window handle used for dragging the dock window, and the splitter handle used to resize the dock window in relation to other dock windows using a splitter. (The splitter handle is only visible for docked windows.)

This enum specifies where the dock window splitter handle is placed in the dock area.

Normal The splitter handles of dock windows are placed at the right or bottom.

Reverse The splitter handles of dock windows are placed at the left or top.

Definition at line 111 of file q3dockarea.h.

00111 { Normal, Reverse };


Constructor & Destructor Documentation

Q3DockArea::Q3DockArea ( Qt::Orientation  o,
HandlePosition  h = Normal,
QWidget parent = 0,
const char *  name = 0 
)

Constructs a Q3DockArea with orientation o, HandlePosition h, parent parent and called name.

Definition at line 548 of file q3dockarea.cpp.

References dockWindows, QObject::installEventFilter(), QWidget::layout(), and Q3DockAreaLayout.

00549     : QWidget(parent, name), orient(o), layout(0), hPos(h)
00550 {
00551     layout = new Q3DockAreaLayout(this, o, &dockWindows, 0, 0, "toollayout");
00552     installEventFilter(this);
00553 }

Here is the call graph for this function:

Q3DockArea::~Q3DockArea (  ) 

Destroys the dock area and all the dock windows docked in the dock area.

Does not affect any floating dock windows or dock windows in other dock areas, even if they first appeared in this dock area. Floating dock windows are effectively top level windows and are not child windows of the dock area. When a floating dock window is docked (dragged into a dock area) its parent becomes the dock area.

Definition at line 567 of file q3dockarea.cpp.

References dockWindows, QList< T >::isEmpty(), and QList< T >::takeFirst().

00568 {
00569     while (!dockWindows.isEmpty())
00570         delete dockWindows.takeFirst();
00571 }

Here is the call graph for this function:


Member Function Documentation

void Q3DockArea::moveDockWindow ( Q3DockWindow w,
const QPoint p,
const QRect r,
bool  swap 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Moves the dock window w inside the dock area where p is the new position (in global screen coordinates), r is the suggested rectangle of the dock window and swap specifies whether or not the orientation of the docked widget needs to be changed.

This function is used internally by Q3DockWindow. You shouldn't need to call it yourself.

Definition at line 660 of file q3dockarea.cpp.

References QList< T >::append(), QList< T >::at(), QList< T >::begin(), QRect::contains(), QList< T >::contains(), QList< T >::count(), dockWindow(), dockWindows, QList< T >::end(), QSizePolicy::Expanding, findDockWindow(), fix_pos(), QWidget::height(), QRect::height(), Qt::Horizontal, i, index, QList< T >::indexOf(), QList< T >::insert(), int, invalidateFixedSizes(), QList< T >::isEmpty(), QWidget::layout(), lineOf(), qdesigner_internal::lineRect(), QWidget::mapFromGlobal(), QSizePolicy::Minimum, QWidget::minimumHeight(), QWidget::minimumWidth(), Q3DockWindow::newLine(), orientation(), p, point_pos(), QWidget::pos(), qDebug(), qMax(), qMin(), QWidget::rect(), QPoint::rx(), Q3DockWindow::setFixedExtentWidth(), Q3DockWindow::setNewLine(), QWidget::setSizePolicy(), QRect::size(), QList< T >::size(), size_extent(), QList< T >::takeAt(), QRect::topLeft(), updateLayout(), Qt::Vertical, w, QRect::width(), QWidget::width(), QRect::x(), QPoint::x(), and QRect::y().

Referenced by Q3DockWindow::init(), and Q3DockWindow::updatePosition().

00661 {
00662     invalidateFixedSizes();
00663     int mse = -10;
00664     bool hasResizable = false;
00665     for (int i = 0; i < dockWindows.size(); ++i) {
00666         Q3DockWindow *dw = dockWindows.at(i);
00667         if (dw->isHidden())
00668             continue;
00669         if (dw->isResizeEnabled())
00670             hasResizable = true;
00671         if (orientation() != Qt::Horizontal)
00672             mse = qMax(qMax(dw->fixedExtent().width(), dw->width()), mse);
00673         else
00674             mse = qMax(qMax(dw->fixedExtent().height(), dw->height()), mse);
00675     }
00676     if (!hasResizable && w->isResizeEnabled()) {
00677         if (orientation() != Qt::Horizontal)
00678             mse = qMax(w->fixedExtent().width(), mse);
00679         else
00680             mse = qMax(w->fixedExtent().height(), mse);
00681     }
00682 
00683     Q3DockWindow *dockWindow = 0;
00684     int dockWindowIndex = findDockWindow(w);
00685     QList<Q3DockWindow *> lineStarts = layout->lineStarts();
00686     QList<QRect> lines = layout->lineList();
00687     bool wasAloneInLine = false;
00688     QPoint pos = mapFromGlobal(p);
00689     int line = lineOf(dockWindowIndex);
00690     QRect lr;
00691     if (line < lines.size())
00692         lr = lines.at(line);
00693     if (dockWindowIndex != -1) {
00694         if (lineStarts.contains(w)
00695             && ((dockWindowIndex < dockWindows.count() - 1
00696                  && lineStarts.contains(dockWindows.at(dockWindowIndex + 1)))
00697                 || dockWindowIndex == dockWindows.count() - 1))
00698             wasAloneInLine = true;
00699         dockWindow = dockWindows.takeAt(dockWindowIndex);
00700         if (!wasAloneInLine) { // only do the pre-layout if the widget isn't the only one in its line
00701             if (lineStarts.contains(dockWindow) && dockWindowIndex < dockWindows.count())
00702                 dockWindows.at(dockWindowIndex)->setNewLine(true);
00703             layout->layoutItems(QRect(0, 0, width(), height()), true);
00704         }
00705     } else {
00706         dockWindow = w;
00707         bool vis = dockWindow->isVisible();
00708         dockWindow->setParent(this);
00709         dockWindow->move(0, 0);
00710         if(vis)
00711             dockWindow->show();
00712         if (swap)
00713             dockWindow->resize(dockWindow->height(), dockWindow->width());
00714         w->installEventFilter(this);
00715     }
00716 
00717     lineStarts = layout->lineStarts();
00718     lines = layout->lineList();
00719 
00720     QRect rect = QRect(mapFromGlobal(r.topLeft()), r.size());
00721     if (orientation() == Qt::Horizontal && QApplication::reverseLayout()) {
00722         rect = QRect(width() - rect.x() - rect.width(), rect.y(), rect.width(), rect.height());
00723         pos.rx() = width() - pos.x();
00724     }
00725     dockWindow->setOffset(point_pos(rect.topLeft(), orientation()));
00726     if (orientation() == Qt::Horizontal) {
00727         int offs = dockWindow->offset();
00728         if (width() - offs < dockWindow->minimumWidth())
00729             dockWindow->setOffset(width() - dockWindow->minimumWidth());
00730     } else {
00731         int offs = dockWindow->offset();
00732         if (height() - offs < dockWindow->minimumHeight())
00733             dockWindow->setOffset(height() - dockWindow->minimumHeight());
00734     }
00735 
00736     if (dockWindows.isEmpty()) {
00737         dockWindows.append(dockWindow);
00738     } else {
00739         int dockLine = -1;
00740         bool insertLine = false;
00741         int i = 0;
00742         QRect lineRect;
00743         // find the line which we touched with the mouse
00744         for (QList<QRect>::Iterator it = lines.begin(); it != lines.end(); ++it, ++i) {
00745             if (point_pos(pos, orientation(), true) >= point_pos((*it).topLeft(), orientation(), true) &&
00746                  point_pos(pos, orientation(), true) <= point_pos((*it).topLeft(), orientation(), true) +
00747                  size_extent((*it).size(), orientation(), true)) {
00748                 dockLine = i;
00749                 lineRect = *it;
00750                 break;
00751             }
00752         }
00753         if (dockLine == -1) { // outside the dock...
00754             insertLine = true;
00755             if (point_pos(pos, orientation(), true) < 0) // insert as first line
00756                 dockLine = 0;
00757             else
00758                 dockLine = (int)lines.count(); // insert after the last line ### size_t/int cast
00759         } else { // inside the dock (we have found a dockLine)
00760             if (point_pos(pos, orientation(), true) <
00761                  point_pos(lineRect.topLeft(), orientation(), true) + 4) {        // mouse was at the very beginning of the line
00762                 insertLine = true;                                        // insert a new line before that with the docking widget
00763             } else if (point_pos(pos, orientation(), true) >
00764                         point_pos(lineRect.topLeft(), orientation(), true) +
00765                         size_extent(lineRect.size(), orientation(), true) - 4) {        // mouse was at the very and of the line
00766                 insertLine = true;                                                // insert a line after that with the docking widget
00767                 dockLine++;
00768             }
00769         }
00770 
00771         if (!insertLine && wasAloneInLine && lr.contains(pos)) // if we are alone in a line and just moved in there, re-insert it
00772             insertLine = true;
00773 
00774 #if defined(QDOCKAREA_DEBUG)
00775         qDebug("insert in line %d, and insert that line: %d", dockLine, insertLine);
00776         qDebug("     (btw, we have %d lines)", lines.count());
00777 #endif
00778         Q3DockWindow *dw = 0;
00779         if (dockLine >= (int)lines.count()) { // insert after last line
00780             dockWindows.append(dockWindow);
00781             dockWindow->setNewLine(true);
00782 #if defined(QDOCKAREA_DEBUG)
00783             qDebug("insert at the end");
00784 #endif
00785         } else if (dockLine == 0 && insertLine) { // insert before first line
00786             dockWindows.insert(0, dockWindow);
00787             dockWindows.at(1)->setNewLine(true);
00788 #if defined(QDOCKAREA_DEBUG)
00789             qDebug("insert at the begin");
00790 #endif
00791         } else { // insert somewhere in between
00792             // make sure each line start has a new line
00793             for (int i = 0; i < lineStarts.size(); ++i) {
00794                 dw = lineStarts.at(i);
00795                 dw->setNewLine(true);
00796             }
00797 
00798             // find the index of the first widget in the search line
00799             int searchLine = dockLine;
00800 #if defined(QDOCKAREA_DEBUG)
00801             qDebug("search line start of %d", searchLine);
00802 #endif
00803             Q3DockWindow *lsw = lineStarts.at(searchLine);
00804             int index = dockWindows.indexOf(lsw);
00805             if (index == -1) { // the linestart widget hasn't been found, try to find it harder
00806                 if (lsw == w && dockWindowIndex <= dockWindows.count())
00807                     index = dockWindowIndex;
00808                 else
00809                     index = 0;
00810             }
00811 #if defined(QDOCKAREA_DEBUG)
00812             qDebug("     which starts at %d", index);
00813 #endif
00814             if (!insertLine) { // if we insert the docking widget in the existing line
00815                 // find the index for the widget
00816                 bool inc = true;
00817                 bool firstTime = true;
00818                 for (int i = index; i < dockWindows.size(); ++i) {
00819                     dw = dockWindows.at(i);
00820                     if (orientation() == Qt::Horizontal)
00821                         dw->setFixedExtentWidth(-1);
00822                     else
00823                         dw->setFixedExtentHeight(-1);
00824                     if (!firstTime && lineStarts.contains(dw)) // we are in the next line, so break
00825                         break;
00826                     if (point_pos(pos, orientation()) <
00827                          point_pos(fix_pos(dw), orientation()) + size_extent(dw->size(), orientation()) / 2) {
00828                         inc = false;
00829                     }
00830                     if (inc)
00831                         index++;
00832                     firstTime = false;
00833                 }
00834 #if defined(QDOCKAREA_DEBUG)
00835                 qDebug("insert at index: %d", index);
00836 #endif
00837                 // if we insert it just before a widget which has a new line, transfer the newline to the docking widget
00838                 // but not if we didn't only mave a widget in its line which was alone in the line before
00839                 if (!(wasAloneInLine && lr.contains(pos))
00840                      && index >= 0 && index < dockWindows.count() &&
00841                      dockWindows.at(index)->newLine() && lineOf(index) == dockLine) {
00842 #if defined(QDOCKAREA_DEBUG)
00843                     qDebug("get rid of the old newline and get me one");
00844 #endif
00845                     dockWindows.at(index)->setNewLine(false);
00846                     dockWindow->setNewLine(true);
00847                 } else if (wasAloneInLine && lr.contains(pos)) {
00848                     dockWindow->setNewLine(true);
00849                 } else { // if we are somewhere in a line, get rid of the newline
00850                     dockWindow->setNewLine(false);
00851                 }
00852             } else { // insert in a new line, so make sure the dock widget and the widget which will be after it have a newline
00853 #if defined(QDOCKAREA_DEBUG)
00854                 qDebug("insert a new line");
00855 #endif
00856                 if (index < dockWindows.count()) {
00857 #if defined(QDOCKAREA_DEBUG)
00858                     qDebug("give the widget at %d a newline", index);
00859 #endif
00860                     Q3DockWindow* nldw = dockWindows.at(index);
00861                     if (nldw)
00862                         nldw->setNewLine(true);
00863                 }
00864 #if defined(QDOCKAREA_DEBUG)
00865                 qDebug("give me a newline");
00866 #endif
00867                 dockWindow->setNewLine(true);
00868             }
00869             // finally insert the widget
00870             dockWindows.insert(index, dockWindow);
00871         }
00872     }
00873 
00874     if (mse != -10 && w->isResizeEnabled()) {
00875         if (orientation() != Qt::Horizontal)
00876             w->setFixedExtentWidth(qMin(qMax(w->minimumWidth(), mse), w->sizeHint().width()));
00877         else
00878             w->setFixedExtentHeight(qMin(qMax(w->minimumHeight(), mse), w->sizeHint().height()));
00879     }
00880 
00881     updateLayout();
00882     setSizePolicy(QSizePolicy(orientation() == Qt::Horizontal ? QSizePolicy::Expanding : QSizePolicy::Minimum,
00883                                 orientation() == Qt::Vertical ? QSizePolicy::Expanding : QSizePolicy::Minimum));
00884 }

Here is the call graph for this function:

void Q3DockArea::removeDockWindow ( Q3DockWindow w,
bool  makeFloating,
bool  swap,
bool  fixNewLines = true 
)

Removes the dock window w from the dock area. If makeFloating is true, w gets floated, and if swap is true, the orientation of w gets swapped. If fixNewLines is true (the default) newlines in the area will be fixed.

You should never need to call this function yourself. Use Q3DockWindow::dock() and Q3DockWindow::undock() instead.

Definition at line 896 of file q3dockarea.cpp.

References QList< T >::at(), QList< T >::contains(), QList< T >::count(), dockWindow(), dockWindows, findDockWindow(), i, QList< T >::isEmpty(), QWidget::layout(), p, QWidget::parentWidget(), QSizePolicy::Preferred, QList< T >::removeAt(), Q3DockWindow::setNewLine(), QWidget::setSizePolicy(), updateLayout(), w, and QWidget::window().

Referenced by eventFilter(), Q3DockWindow::removeFromDock(), Q3DockWindow::undock(), Q3DockWindow::updatePosition(), and Q3DockWindow::~Q3DockWindow().

00897 {
00898     w->removeEventFilter(this);
00899     Q3DockWindow *dockWindow = 0;
00900     int i = findDockWindow(w);
00901     if (i == -1)
00902         return;
00903     dockWindow = dockWindows.at(i);
00904     dockWindows.removeAt(i);
00905     QList<Q3DockWindow *> lineStarts = layout->lineStarts();
00906     if (fixNewLines && lineStarts.contains(dockWindow) && i < dockWindows.count())
00907         dockWindows.at(i)->setNewLine(true);
00908     if (makeFloating) {
00909         QWidget *p = parentWidget() ? parentWidget() : window();
00910         dockWindow->setParent(p, Qt::WType_Dialog | Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool);
00911         dockWindow->move(0, 0);
00912     }
00913     if (swap)
00914         dockWindow->resize(dockWindow->height(), dockWindow->width());
00915     updateLayout();
00916     if (dockWindows.isEmpty())
00917         setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00918 }

Here is the call graph for this function:

void Q3DockArea::moveDockWindow ( Q3DockWindow w,
int  index = -1 
)

Moves the Q3DockWindow w within the dock area. If w is not already docked in this area, w is docked first. If index is -1 or larger than the number of docked widgets, w is appended at the end, otherwise it is inserted at the position index.

Definition at line 580 of file q3dockarea.cpp.

References QList< T >::append(), QList< T >::count(), dockWindow(), dockWindows, QSizePolicy::Expanding, findDockWindow(), Qt::Horizontal, Q3DockWindow::InDock, QList< T >::insert(), invalidateFixedSizes(), QSizePolicy::Minimum, orientation(), QList< T >::removeAll(), QWidget::setSizePolicy(), updateLayout(), Qt::Vertical, and w.

00581 {
00582     invalidateFixedSizes();
00583     Q3DockWindow *dockWindow = 0;
00584     int dockWindowIndex = findDockWindow(w);
00585     if (dockWindowIndex == -1) {
00586         dockWindow = w;
00587         bool vis = dockWindow->isVisible();
00588         dockWindow->setParent(this);
00589         dockWindow->move(0, 0);
00590         if(vis)
00591             dockWindow->show();
00592         w->installEventFilter(this);
00593         updateLayout();
00594         setSizePolicy(QSizePolicy(orientation() == Qt::Horizontal ? QSizePolicy::Expanding : QSizePolicy::Minimum,
00595                                     orientation() == Qt::Vertical ? QSizePolicy::Expanding : QSizePolicy::Minimum));
00596         dockWindows.append(w);
00597     } else {
00598         if (w->parent() != this) {
00599             bool vis = w->isVisible();
00600             w->setParent(this);
00601             w->move(0, 0);
00602             if(vis)
00603                 w->show();
00604         }
00605         if (index == -1) {
00606             dockWindows.removeAll(w);
00607             dockWindows.append(w);
00608         }
00609     }
00610 
00611     w->dockArea = this;
00612     w->curPlace = Q3DockWindow::InDock;
00613     w->updateGui();
00614 
00615     if (index != -1 && index < (int)dockWindows.count()) {
00616         dockWindows.removeAll(w);
00617         dockWindows.insert(index, w);
00618     }
00619 }

Here is the call graph for this function:

bool Q3DockArea::hasDockWindow ( Q3DockWindow w,
int *  index = 0 
)

Returns true if the dock area contains the dock window w; otherwise returns false. If index is not 0 it will be set as follows: if the dock area contains the dock window *{index} is set to w's index position; otherwise *{index} is set to -1.

Definition at line 628 of file q3dockarea.cpp.

References dockWindows, i, QList< T >::indexOf(), and w.

00629 {
00630     int i = dockWindows.indexOf(w);
00631     if (index)
00632         *index = i;
00633     return i != -1;
00634 }

Here is the call graph for this function:

void Q3DockArea::invalidNextOffset ( Q3DockWindow dw  ) 

Definition at line 953 of file q3dockarea.cpp.

References QList< T >::at(), QList< T >::count(), dockWindows, i, QList< T >::indexOf(), and Q3DockWindow::setOffset().

Referenced by Q3DockWindowResizeHandle::mouseReleaseEvent().

00954 {
00955     int i = dockWindows.indexOf(dw);
00956     if (i == -1 || i >= (int)dockWindows.count() - 1)
00957         return;
00958     if ((dw = dockWindows.at(++i)))
00959         dw->setOffset(0);
00960 }

Here is the call graph for this function:

Qt::Orientation Q3DockArea::orientation (  )  const [inline]

Definition at line 123 of file q3dockarea.h.

References orient.

Referenced by dockWindow(), dockWindowData(), Q3DockWindow::handleMove(), invalidateFixedSizes(), isLastDockWindow(), maxSpace(), Q3DockWindowResizeHandle::mouseMoveEvent(), Q3DockWindowResizeHandle::mouseReleaseEvent(), moveDockWindow(), Q3DockWindow::orientation(), Q3DockWindowHandle::paintEvent(), setFixedExtent(), Q3DockWindowResizeHandle::sizeHint(), and Q3DockWindowHandle::updateGui().

00123 { return orient; }

HandlePosition Q3DockArea::handlePosition (  )  const [inline]

Definition at line 124 of file q3dockarea.h.

References hPos.

Referenced by Q3DockWindowResizeHandle::mouseReleaseEvent().

00124 { return hPos; }

bool Q3DockArea::eventFilter ( QObject o,
QEvent e 
) [virtual]

Reimplemented from QObject.

Definition at line 934 of file q3dockarea.cpp.

References QEvent::Close, o, removeDockWindow(), QCoreApplication::sendEvent(), and QEvent::type().

00935 {
00936     if (e->type() == QEvent::Close) {
00937         if (qobject_cast<Q3DockWindow*>(o)) {
00938             o->removeEventFilter(this);
00939             QApplication::sendEvent(o, e);
00940             if (((QCloseEvent*)e)->isAccepted())
00941                 removeDockWindow((Q3DockWindow*)o, false, false);
00942             return true;
00943         }
00944     }
00945     return false;
00946 }

Here is the call graph for this function:

bool Q3DockArea::isEmpty (  )  const

Definition at line 976 of file q3dockarea.cpp.

References dockWindows, and QList< T >::isEmpty().

Referenced by Q3MainWindowLayout::extraPixels().

00977 {
00978     return dockWindows.isEmpty();
00979 }

Here is the call graph for this function:

int Q3DockArea::count (  )  const

Definition at line 966 of file q3dockarea.cpp.

References QList< T >::count(), and dockWindows.

00967 {
00968     return dockWindows.count();
00969 }

Here is the call graph for this function:

QList< Q3DockWindow * > Q3DockArea::dockWindowList (  )  const

Returns a list of the dock windows in the dock area.

Definition at line 986 of file q3dockarea.cpp.

References dockWindows.

Referenced by operator<<(), and operator>>().

00987 {
00988     return dockWindows;
00989 }

bool Q3DockArea::isDockWindowAccepted ( Q3DockWindow dw  ) 

Returns true if dock window dw could be docked into the dock area; otherwise returns false.

See also:
setAcceptDockWindow()

Definition at line 1094 of file q3dockarea.cpp.

References QList< T >::contains(), forbiddenWidgets, Q3MainWindow::hasDockWindow(), Q3MainWindow::isDockEnabled(), and QWidget::parentWidget().

01095 {
01096     if (!dw)
01097         return false;
01098     if (forbiddenWidgets.contains(dw))
01099         return false;
01100 
01101     Q3MainWindow *mw = qobject_cast<Q3MainWindow*>(parentWidget());
01102     if (!mw)
01103         return true;
01104     if (!mw->hasDockWindow(dw))
01105         return false;
01106     if (!mw->isDockEnabled(this))
01107         return false;
01108     if (!mw->isDockEnabled(dw, this))
01109         return false;
01110     return true;
01111 }

Here is the call graph for this function:

void Q3DockArea::setAcceptDockWindow ( Q3DockWindow dw,
bool  accept 
)

If accept is true, dock window dw can be docked in the dock area. If accept is false, dock window dw cannot be docked in the dock area.

See also:
isDockWindowAccepted()

Definition at line 1121 of file q3dockarea.cpp.

References QList< T >::append(), QList< T >::contains(), forbiddenWidgets, and QList< T >::removeAll().

Referenced by Q3MainWindow::setDockEnabled().

01122 {
01123     if (accept)
01124         forbiddenWidgets.removeAll(dw);
01125     else if (forbiddenWidgets.contains(dw))
01126         forbiddenWidgets.append(dw);
01127 }

Here is the call graph for this function:

void Q3DockArea::lineUp ( bool  keepNewLines  )  [slot]

Lines up the dock windows in this dock area to minimize wasted space. If keepNewLines is true, only space within lines is cleaned up. If keepNewLines is false the number of lines might be changed.

Definition at line 998 of file q3dockarea.cpp.

References QLayout::activate(), QList< T >::at(), dockWindows, i, QWidget::layout(), Q3DockWindow::setOffset(), and QList< T >::size().

00999 {
01000     for (int i = 0; i < dockWindows.size(); ++i) {
01001         Q3DockWindow *dw = dockWindows.at(i);
01002         dw->setOffset(0);
01003         if (!keepNewLines)
01004             dw->setNewLine(false);
01005     }
01006     layout->activate();
01007 }

int Q3DockArea::findDockWindow ( Q3DockWindow w  )  [private]

Definition at line 920 of file q3dockarea.cpp.

References dockWindows, QList< T >::indexOf(), and w.

Referenced by dockWindowData(), maxSpace(), moveDockWindow(), and removeDockWindow().

00921 {
00922     return dockWindows.indexOf(w);
00923 }

Here is the call graph for this function:

int Q3DockArea::lineOf ( int  index  )  [private]

Definition at line 636 of file q3dockarea.cpp.

References QList< T >::at(), dockWindows, i, QList< T >::indexOf(), QWidget::layout(), QList< T >::size(), and w.

Referenced by dockWindow(), and moveDockWindow().

00637 {
00638     QList<Q3DockWindow *> lineStarts = layout->lineStarts();
00639     int i = 0;
00640     for (; i < lineStarts.size(); ++i) {
00641         Q3DockWindow *w = lineStarts.at(i);
00642         if (dockWindows.indexOf(w) >= index)
00643             return i;
00644     }
00645     return i;
00646 }

Here is the call graph for this function:

Q3DockArea::DockWindowData * Q3DockArea::dockWindowData ( Q3DockWindow w  )  [private]

Definition at line 1009 of file q3dockarea.cpp.

References QList< T >::at(), QList< T >::contains(), data, dockWindows, findDockWindow(), fix_x(), i, j, QWidget::layout(), orientation(), point_pos(), QList< T >::size(), and w.

Referenced by Q3DockWindow::undock(), and Q3DockWindow::updatePosition().

01010 {
01011     DockWindowData *data = new DockWindowData;
01012     data->index = findDockWindow(w);
01013     if (data->index == -1) {
01014         delete data;
01015         return 0;
01016     }
01017     QList<Q3DockWindow *> lineStarts = layout->lineStarts();
01018     int i = -1;
01019     for (int j = 0; j < dockWindows.size(); ++j) {
01020         Q3DockWindow *dw = dockWindows.at(j);
01021         if (lineStarts.contains(dw))
01022             ++i;
01023         if (dw == w)
01024             break;
01025     }
01026     data->line = i;
01027     data->offset = point_pos(QPoint(fix_x(w), w->y()), orientation());
01028     data->area = this;
01029     data->fixedExtent = w->fixedExtent();
01030     return data;
01031 }

Here is the call graph for this function:

void Q3DockArea::dockWindow ( Q3DockWindow dockWindow,
DockWindowData data 
) [private]

Definition at line 1033 of file q3dockarea.cpp.

References QList< T >::append(), QList< T >::at(), QList< T >::contains(), QList< T >::count(), data, dockWindows, QSizePolicy::Expanding, fix_pos(), Qt::Horizontal, i, index, QList< T >::indexOf(), QList< T >::insert(), QList< T >::isEmpty(), QWidget::layout(), lineOf(), QSizePolicy::Minimum, Q3DockWindow::newLine(), orientation(), point_pos(), Q3DockWindow::setNewLine(), QWidget::setSizePolicy(), QList< T >::size(), size_extent(), updateLayout(), and Qt::Vertical.

Referenced by Q3DockWindow::dock(), moveDockWindow(), and removeDockWindow().

01034 {
01035     if (!data)
01036         return;
01037 
01038     dockWindow->setParent(this);
01039     dockWindow->move(0, 0);
01040 
01041     dockWindow->installEventFilter(this);
01042     dockWindow->dockArea = this;
01043     dockWindow->updateGui();
01044 
01045     if (dockWindows.isEmpty()) {
01046         dockWindows.append(dockWindow);
01047     } else {
01048         QList<Q3DockWindow *> lineStarts = layout->lineStarts();
01049         int index = 0;
01050         if (lineStarts.count() > data->line)
01051             index = dockWindows.indexOf(lineStarts.at(data->line));
01052         if (index == -1)
01053             index = 0;
01054         bool firstTime = true;
01055         int offset = data->offset;
01056         for (int i = index; i < dockWindows.size(); ++i) {
01057             Q3DockWindow *dw = dockWindows.at(i);
01058             if (!firstTime && lineStarts.contains(dw))
01059                 break;
01060             if (offset <
01061                  point_pos(fix_pos(dw), orientation()) + size_extent(dw->size(), orientation()) / 2)
01062                 break;
01063             index++;
01064             firstTime = false;
01065         }
01066         if (index >= 0 && index < dockWindows.count() &&
01067              dockWindows.at(index)->newLine() && lineOf(index) == data->line) {
01068             dockWindows.at(index)->setNewLine(false);
01069             dockWindow->setNewLine(true);
01070         } else {
01071             dockWindow->setNewLine(false);
01072         }
01073 
01074         dockWindows.insert(index, dockWindow);
01075     }
01076     dockWindow->show();
01077 
01078     dockWindow->setFixedExtentWidth(data->fixedExtent.width());
01079     dockWindow->setFixedExtentHeight(data->fixedExtent.height());
01080 
01081     updateLayout();
01082     setSizePolicy(QSizePolicy(orientation() == Qt::Horizontal ? QSizePolicy::Expanding : QSizePolicy::Minimum,
01083                                 orientation() == Qt::Vertical ? QSizePolicy::Expanding : QSizePolicy::Minimum));
01084 
01085 }

Here is the call graph for this function:

void Q3DockArea::updateLayout (  )  [private]

Definition at line 925 of file q3dockarea.cpp.

References QLayout::activate(), QLayout::invalidate(), and QWidget::layout().

Referenced by dockWindow(), moveDockWindow(), and removeDockWindow().

00926 {
00927     layout->invalidate();
00928     layout->activate();
00929 }

Here is the call graph for this function:

void Q3DockArea::invalidateFixedSizes (  )  [private]

Definition at line 1129 of file q3dockarea.cpp.

References QList< T >::at(), dockWindows, Qt::Horizontal, i, orientation(), Q3DockWindow::setFixedExtentWidth(), and QList< T >::size().

Referenced by moveDockWindow().

01130 {
01131     for (int i = 0; i < dockWindows.size(); ++i) {
01132         Q3DockWindow *dw = dockWindows.at(i);
01133         if (orientation() == Qt::Horizontal)
01134             dw->setFixedExtentWidth(-1);
01135         else
01136             dw->setFixedExtentHeight(-1);
01137     }
01138 }

Here is the call graph for this function:

int Q3DockArea::maxSpace ( int  hint,
Q3DockWindow dw 
) [private]

Definition at line 1140 of file q3dockarea.cpp.

References QList< T >::at(), QList< T >::count(), diff(), dockWindows, findDockWindow(), QWidget::height(), Qt::Horizontal, i, index, int, orientation(), qMax(), tb, w, and QWidget::width().

Referenced by Q3DockWindowResizeHandle::mouseReleaseEvent().

01141 {
01142     int index = findDockWindow(dw);
01143     if (index == -1 || index + 1 >= (int)dockWindows.count()) {
01144         if (orientation() == Qt::Horizontal)
01145             return dw->width();
01146         return dw->height();
01147     }
01148 
01149     Q3DockWindow *w = 0;
01150     int i = 0;
01151     do {
01152         w = dockWindows.at(index + (++i));
01153     } while (i + 1 < (int)dockWindows.count() && (!w || w->isHidden()));
01154     if (!w || !w->isResizeEnabled() || i >= (int)dockWindows.count()) {
01155         if (orientation() == Qt::Horizontal)
01156             return dw->width();
01157         return dw->height();
01158     }
01159     int min = 0;
01160     Q3ToolBar *tb = qobject_cast<Q3ToolBar*>(w);
01161     if (orientation() == Qt::Horizontal) {
01162         w->setFixedExtentWidth(-1);
01163         if (!tb)
01164             min = qMax(w->minimumSize().width(), w->minimumSizeHint().width());
01165         else
01166             min = w->sizeHint().width();
01167     } else {
01168         w->setFixedExtentHeight(-1);
01169         if (!tb)
01170             min = qMax(w->minimumSize().height(), w->minimumSizeHint().height());
01171         else
01172             min = w->sizeHint().height();
01173     }
01174 
01175     int diff = hint - (orientation() == Qt::Horizontal ? dw->width() : dw->height());
01176 
01177     if ((orientation() == Qt::Horizontal ? w->width() : w->height()) - diff < min)
01178         hint = (orientation() == Qt::Horizontal ? dw->width() : dw->height()) + (orientation() == Qt::Horizontal ? w->width() : w->height()) - min;
01179 
01180     diff = hint - (orientation() == Qt::Horizontal ? dw->width() : dw->height());
01181     if (orientation() == Qt::Horizontal)
01182         w->setFixedExtentWidth(w->width() - diff);
01183     else
01184         w->setFixedExtentHeight(w->height() - diff);
01185     return hint;
01186 }

Here is the call graph for this function:

void Q3DockArea::setFixedExtent ( int  d,
Q3DockWindow dw 
) [private]

Definition at line 1188 of file q3dockarea.cpp.

References QList< T >::append(), QList< T >::at(), dockWindows, Qt::Horizontal, i, orientation(), qMax(), QList< T >::size(), w, QWidget::x(), and QWidget::y().

Referenced by Q3DockWindowResizeHandle::mouseReleaseEvent().

01189 {
01190     QList<Q3DockWindow *> lst;
01191     for (int i = 0; i < dockWindows.size(); ++i) {
01192         Q3DockWindow *w = dockWindows.at(i);
01193         if (w->isHidden())
01194             continue;
01195         if (orientation() == Qt::Horizontal) {
01196             if (dw->y() != w->y())
01197                 continue;
01198         } else {
01199             if (dw->x() != w->x())
01200                 continue;
01201         }
01202         if (orientation() == Qt::Horizontal)
01203             d = qMax(d, w->minimumHeight());
01204         else
01205             d = qMax(d, w->minimumWidth());
01206         if (w->isResizeEnabled())
01207             lst.append(w);
01208     }
01209     for (int i = 0; i < lst.size(); ++i) {
01210         Q3DockWindow *w = lst.at(i);
01211         if (orientation() == Qt::Horizontal)
01212             w->setFixedExtentHeight(d);
01213         else
01214             w->setFixedExtentWidth(d);
01215     }
01216 }

Here is the call graph for this function:

bool Q3DockArea::isLastDockWindow ( Q3DockWindow dw  )  [private]

Definition at line 1218 of file q3dockarea.cpp.

References QList< T >::at(), QList< T >::count(), dockWindows, Qt::Horizontal, i, QList< T >::indexOf(), orientation(), Qt::Vertical, w, QWidget::x(), and QWidget::y().

01219 {
01220     int i = dockWindows.indexOf(dw);
01221     if (i == -1 || i >= (int)dockWindows.count() - 1)
01222         return true;
01223     Q3DockWindow *w = 0;
01224     if ((w = dockWindows.at(++i))) {
01225         if (orientation() == Qt::Horizontal && dw->y() < w->y())
01226             return true;
01227         if (orientation() == Qt::Vertical && dw->x() < w->x())
01228             return true;
01229     } else {
01230         return true;
01231     }
01232     return false;
01233 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Q3DockWindow [friend]

Definition at line 106 of file q3dockarea.h.

friend class Q3DockWindowResizeHandle [friend]

Definition at line 107 of file q3dockarea.h.

friend class Q3DockAreaLayout [friend]

Definition at line 108 of file q3dockarea.h.

Referenced by Q3DockArea().

QTextStream & operator<< ( QTextStream ts,
const Q3DockArea dockArea 
) [related]

Writes the layout of the dock windows in dock area dockArea to the text stream ts.

Definition at line 1244 of file q3dockarea.cpp.

References dockWindowList(), QTextStream::endl(), i, l, and QString::number().

01245 {
01246     QString str;
01247     QList<Q3DockWindow *> l = dockArea.dockWindowList();
01248 
01249     for (int i = 0; i < l.size(); ++i) {
01250         Q3DockWindow *dw = l.at(i);
01251         str += "[" + QString(dw->windowTitle()) + "," + QString::number((int)dw->offset()) +
01252                "," + QString::number((int)dw->newLine()) + "," + QString::number(dw->fixedExtent().width()) +
01253                "," + QString::number(dw->fixedExtent().height()) + "," + QString::number((int)!dw->isHidden()) + "]";
01254     }
01255     ts << str << endl;
01256 
01257     return ts;
01258 }

Here is the call graph for this function:

QTextStream & operator>> ( QTextStream ts,
Q3DockArea dockArea 
) [related]

Reads the layout description of the dock windows in dock area dockArea from the text stream ts and restores it. The layout description must have been previously written by the operator<<() function.

Definition at line 1269 of file q3dockarea.cpp.

References c, dockWindowList(), QCss::Height, height, i, j, l, name, Post, Pre, QTextStream::readLine(), s, QString::toInt(), Width, and width.

01270 {
01271     QString s = ts.readLine();
01272 
01273     QString name, offset, newLine, width, height, visible;
01274 
01275     enum State { Pre, Name, Offset, NewLine, Width, Height, Visible, Post };
01276     int state = Pre;
01277     QChar c;
01278     QList<Q3DockWindow *> l = dockArea.dockWindowList();
01279 
01280     for (int i = 0; i < s.length(); ++i) {
01281         c = s[i];
01282         if (state == Pre && c == '[') {
01283             state++;
01284             continue;
01285         }
01286         if (c == ',' &&
01287              (state == Name || state == Offset || state == NewLine || state == Width || state == Height)) {
01288             state++;
01289             continue;
01290         }
01291         if (state == Visible && c == ']') {
01292             for (int j = 0; j < l.size(); ++j) {
01293                 Q3DockWindow *dw = l.at(j);
01294                 if (QString(dw->windowTitle()) == name) {
01295                     dw->setNewLine((bool)newLine.toInt());
01296                     dw->setOffset(offset.toInt());
01297                     dw->setFixedExtentWidth(width.toInt());
01298                     dw->setFixedExtentHeight(height.toInt());
01299                     if (!(bool)visible.toInt())
01300                         dw->hide();
01301                     else
01302                         dw->show();
01303                     break;
01304                 }
01305             }
01306 
01307             name = offset = newLine = width = height = visible = "";
01308 
01309             state = Pre;
01310             continue;
01311         }
01312         if (state == Name)
01313             name += c;
01314         else if (state == Offset)
01315             offset += c;
01316         else if (state == NewLine)
01317             newLine += c;
01318         else if (state == Width)
01319             width += c;
01320         else if (state == Height)
01321             height += c;
01322         else if (state == Visible)
01323             visible += c;
01324     }
01325 
01326     dockArea.QWidget::layout()->invalidate();
01327     dockArea.QWidget::layout()->activate();
01328     return ts;
01329 }

Here is the call graph for this function:


Member Data Documentation

Qt::Orientation Q3DockArea::orient [private]

Definition at line 160 of file q3dockarea.h.

Referenced by Q3DockAreaLayout::orientation(), and orientation().

QList<Q3DockWindow *> Q3DockArea::dockWindows [private]

Definition at line 161 of file q3dockarea.h.

Referenced by count(), dockWindow(), dockWindowData(), dockWindowList(), findDockWindow(), hasDockWindow(), invalidateFixedSizes(), invalidNextOffset(), isEmpty(), isLastDockWindow(), lineOf(), lineUp(), maxSpace(), moveDockWindow(), Q3DockArea(), removeDockWindow(), setFixedExtent(), and ~Q3DockArea().

Q3DockAreaLayout* Q3DockArea::layout [private]

Definition at line 162 of file q3dockarea.h.

HandlePosition Q3DockArea::hPos [private]

Definition at line 163 of file q3dockarea.h.

Referenced by handlePosition().

QList<Q3DockWindow *> Q3DockArea::forbiddenWidgets [private]

Definition at line 164 of file q3dockarea.h.

Referenced by isDockWindowAccepted(), and setAcceptDockWindow().

Q3DockAreaPrivate* Q3DockArea::d [private]

Definition at line 165 of file q3dockarea.h.


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