Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qtoolbararealayout.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    114114
    115115        QSize sh = item.sizeHint();
    116         a += pick(o, sh) + item.extraSpace;
     116        a += item.preferredSize > 0 ? item.preferredSize : pick(o, sh);
    117117        b = qMax(b, perp(o, sh));
    118118    }
     
    157157            continue;
    158158
    159         QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout());
    160         if (tblayout)
     159        if (QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout()))
    161160            tblayout->checkUsePopupMenu();
    162161
    163         int itemMin = pick(o, item.minimumSize());
    164         int itemHint = pick(o, item.sizeHint());
    165         //we ensure the extraspace is not too low
    166         item.extraSpace = qMax(itemMin - itemHint, item.extraSpace);
    167         itemHint  += item.extraSpace;
    168         int itemExtra = qMin(itemHint - itemMin, extra);
    169 
    170         item.size = itemMin + itemExtra;
    171         extra -= itemExtra;
     162        const int itemMin = pick(o, item.minimumSize());
     163        //preferredSize is the default if it is set, otherwise, we take the sizehint
     164        item.size = item.preferredSize > 0 ? item.preferredSize : pick(o, item.sizeHint());
     165
     166        //the extraspace is the space above the item minimum sizehint
     167        const int extraSpace = qMin(item.size - itemMin, extra);
     168        item.size = itemMin + extraSpace; //that is the real size
     169
     170        extra -= extraSpace;
    172171
    173172        last = i;
     
    396395void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos)
    397396{
    398     if (dirty) {
     397    if (dirty)
    399398        fitLayout();
    400     }
    401399
    402400    dirty = true;
    403401
    404     if (o == Qt::Vertical) {
     402    if (o == Qt::Vertical)
    405403        pos -= rect.top();
    406     }
    407 
    408     //here we actually update the extraSpace for the line containing the toolbar so that we move it
     404
     405    //here we actually update the preferredSize for the line containing the toolbar so that we move it
    409406    for (int j = 0; j < lines.count(); ++j) {
    410407        QToolBarAreaLayoutLine &line = lines[j];
     
    433430                    }
    434431
    435                     //let's update the previous extra space
     432                    //extra is the number of pixels to add to the previous toolbar
    436433                    int extra = newPos - current.pos;
    437434
    438                     if (qAbs(previous.extraSpace + extra) < QApplication::startDragDistance()) {
    439                         //we stick to the default space
    440                         extra = 0;
     435                    //we check if the previous is near its size hint
     436                    //in which case we try to stick to it
     437                    const int diff = pick(o, previous.sizeHint()) - (previous.size + extra);
     438                    if (qAbs(diff) < QApplication::startDragDistance()) {
     439                        //we stick to the default place and size
     440                        extra += diff;
    441441                    }
    442442
    443443                    //update for the current item
    444                     current.extraSpace -= extra;
    445                     //this ensures the toolbars to be pushed to the right when necessary
    446                     current.extraSpace = qMax(pick(o,current.minimumSize())- pick(o,current.sizeHint()), current.extraSpace);
    447  
     444                    current.extendSize(line.o, -extra);
     445
    448446                    if (extra >= 0) {
    449                         previous.extraSpace += extra;
    450 
     447                        previous.extendSize(line.o, extra);
    451448                    } else {
    452449                        //we need to push the toolbars on the left starting with previous
     
    456453                            QToolBarAreaLayoutItem &item = line.toolBarItems[l];
    457454                            if (!item.skip()) {
    458                                 const int minExtraSpace = pick(o, item.minimumSize()) - pick(o, item.sizeHint());
    459                                 const int margin =  item.extraSpace - minExtraSpace;
     455                                const int minPreferredSize = pick(o, item.minimumSize());
     456                                const int margin =  item.size - minPreferredSize;
    460457                                if (margin < extra) {
    461                                     item.extraSpace = minExtraSpace;
     458                                    item.resize(line.o, minPreferredSize);
    462459                                    extra -= margin;
    463460                                } else {
    464                                     item.extraSpace -= extra;
     461                                    item.extendSize(line.o, -extra);
    465462                                    extra = 0;
    466463                                }
     
    484481
    485482
    486 QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const
     483QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const
    487484{
    488485    int p = pick(o, pos);
     
    513510            QList<int> result;
    514511            result << j << k;
     512            *minDistance = 0; //we found a perfect match
    515513            return result;
    516514        }
    517     } else if (appendLineDropRect().contains(pos)) {
    518         QList<int> result;
    519         result << lines.count() << 0;
    520         return result;
     515    } else {
     516        const int dist = distance(pos);
     517        //it will only return a path if the minDistance is higher than the current distance
     518        if (dist >= 0 && *minDistance > dist) {
     519            *minDistance = dist;
     520
     521            QList<int> result;
     522            result << lines.count() << 0;
     523            return result;
     524        }
    521525    }
    522526
     
    524528}
    525529
    526 bool QToolBarAreaLayoutInfo::insertGap(QList<int> path, QLayoutItem *item)
    527 {
    528     int j = path.at(0);
     530bool QToolBarAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *item)
     531{
     532    Q_ASSERT(path.count() == 2);
     533    int j = path.first();
    529534    if (j == lines.count())
    530535        lines.append(QToolBarAreaLayoutLine(o));
     
    537542    gap_item.widgetItem = item;
    538543
    539     //update the previous item's extra space
     544    //update the previous item's preferred size
    540545    for(int p = k - 1 ; p >= 0; --p) {
    541546        QToolBarAreaLayoutItem &previous = line.toolBarItems[p];
    542547        if (!previous.skip()) {
    543548            //we found the previous one
    544             gap_item.extraSpace = qMax(0, previous.extraSpace - pick(o, gap_item.sizeHint()));
    545             previous.extraSpace = qMin(previous.extraSpace, 0);
     549            int previousSizeHint = pick(line.o, previous.sizeHint());
     550            int previousExtraSpace = previous.size - previousSizeHint;
     551
     552            if (previousExtraSpace > 0) {
     553                //in this case we reset the space
     554                previous.preferredSize = -1;
     555                previous.size = previousSizeHint;
     556
     557                gap_item.resize(o, previousExtraSpace);
     558            }
     559
    546560            break;
    547561        }
     
    556570{
    557571    lines.clear();
    558     rect = QRect(0, 0, -1, -1);
    559 }
    560 
    561 QRect QToolBarAreaLayoutInfo::itemRect(QList<int> path) const
    562 {
     572    rect = QRect();
     573}
     574
     575QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const
     576{
     577    Q_ASSERT(path.count() == 2);
    563578    int j = path.at(0);
    564579    int k = path.at(1);
     
    580595}
    581596
    582 QRect QToolBarAreaLayoutInfo::appendLineDropRect() const
    583 {
    584     QRect result;
    585 
     597int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const
     598{
    586599    switch (dockPos) {
    587600        case QInternal::LeftDock:
    588             result = QRect(rect.right(), rect.top(),
    589                             EmptyDockAreaSize, rect.height());
    590             break;
     601            if (pos.y() < rect.bottom())
     602                return pos.x() - rect.right();
    591603        case QInternal::RightDock:
    592             result = QRect(rect.left() - EmptyDockAreaSize, rect.top(),
    593                             EmptyDockAreaSize, rect.height());
    594             break;
     604            if (pos.y() < rect.bottom())
     605                return rect.left() - pos.x();
    595606        case QInternal::TopDock:
    596             result = QRect(rect.left(), rect.bottom() + 1,
    597                             rect.width(), EmptyDockAreaSize);
    598             break;
     607            if (pos.x() < rect.right())
     608                return pos.y() - rect.bottom();
    599609        case QInternal::BottomDock:
    600             result = QRect(rect.left(), rect.top() - EmptyDockAreaSize,
    601                             rect.width(), EmptyDockAreaSize);
    602             break;
     610            if (pos.x() < rect.right())
     611                return rect.top() - pos.y();
    603612        default:
    604613            break;
    605614    }
    606 
    607     return result;
     615    return -1;
    608616}
    609617
     
    612620*/
    613621
    614 QToolBarAreaLayout::QToolBarAreaLayout(QMainWindow *win)
    615 {
    616     visible = true;
    617     mainWindow = win;
     622QToolBarAreaLayout::QToolBarAreaLayout(const QMainWindow *win) : mainWindow(win), visible(true)
     623{
    618624    for (int i = 0; i < QInternal::DockCount; ++i) {
    619625        QInternal::DockPosition pos = static_cast<QInternal::DockPosition>(i);
     
    771777            for (int k = 0; k < line.toolBarItems.count(); ++k) {
    772778                QToolBarAreaLayoutItem &item = line.toolBarItems[k];
    773                 delete item.widgetItem;
     779                if (!item.gap)
     780                    delete item.widgetItem;
    774781                item.widgetItem = 0;
    775782            }
     
    921928                    geo = QStyle::visualRect(dir, line.rect, geo);
    922929
    923                 layout->widgetAnimator->animate(widget, geo, animate);
     930                layout->widgetAnimator.animate(widget, geo, animate);
    924931            }
    925932        }
     
    10161023}
    10171024
     1025//this functions returns the path to the possible gapindex for the position pos
    10181026QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const
    10191027{
    10201028    Qt::LayoutDirection dir = mainWindow->layoutDirection();
     1029    int minDistance = 80; // when a dock area is empty, how "wide" is it?
     1030    QList<int> ret; //return value
    10211031    for (int i = 0; i < QInternal::DockCount; ++i) {
    10221032        QPoint p = pos;
    10231033        if (docks[i].o == Qt::Horizontal)
    10241034            p = QStyle::visualPos(dir, docks[i].rect, p);
    1025         QList<int> result = docks[i].gapIndex(p);
     1035        QList<int> result = docks[i].gapIndex(p, &minDistance);
    10261036        if (!result.isEmpty()) {
    10271037            result.prepend(i);
    1028             return result;
    1029         }
    1030     }
    1031 
    1032     return QList<int>();
     1038            ret = result;
     1039        }
     1040    }
     1041
     1042    return ret;
    10331043}
    10341044
     
    10531063}
    10541064
    1055 bool QToolBarAreaLayout::insertGap(QList<int> path, QLayoutItem *item)
    1056 {
    1057     Q_ASSERT(!path.isEmpty());
    1058     int i = path.takeFirst();
     1065bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item)
     1066{
     1067    Q_ASSERT(path.count() == 3);
     1068    const int i = path.first();
    10591069    Q_ASSERT(i >= 0 && i < QInternal::DockCount);
    1060     return docks[i].insertGap(path, item);
    1061 }
    1062 
    1063 void QToolBarAreaLayout::remove(QList<int> path)
    1064 {
     1070    return docks[i].insertGap(path.mid(1), item);
     1071}
     1072
     1073void QToolBarAreaLayout::remove(const QList<int> &path)
     1074{
     1075    Q_ASSERT(path.count() == 3);
    10651076    docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2));
    10661077}
     
    10901101    for (int i = 0; i < QInternal::DockCount; ++i)
    10911102        docks[i].clear();
    1092     rect = QRect(0, 0, -1, -1);
    1093 }
    1094 
    1095 QToolBarAreaLayoutItem &QToolBarAreaLayout::item(QList<int> path)
     1103    rect = QRect();
     1104}
     1105
     1106QToolBarAreaLayoutItem &QToolBarAreaLayout::item(const QList<int> &path)
    10961107{
    10971108    Q_ASSERT(path.count() == 3);
     
    11051116}
    11061117
    1107 QRect QToolBarAreaLayout::itemRect(QList<int> path) const
    1108 {
    1109     int i = path.takeFirst();
    1110 
    1111     QRect r = docks[i].itemRect(path);
     1118QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const
     1119{
     1120    const int i = path.first();
     1121
     1122    QRect r = docks[i].itemRect(path.mid(1));
    11121123    if (docks[i].o == Qt::Horizontal)
    11131124        r = QStyle::visualRect(mainWindow->layoutDirection(),
     
    11161127}
    11171128
    1118 QLayoutItem *QToolBarAreaLayout::plug(QList<int> path)
     1129QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path)
    11191130{
    11201131    QToolBarAreaLayoutItem &item = this->item(path);
     
    11251136}
    11261137
    1127 QLayoutItem *QToolBarAreaLayout::unplug(QList<int> path, QToolBarAreaLayout *other)
     1138QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other)
    11281139{
    11291140    //other needs to be update as well
     1141    Q_ASSERT(path.count() == 3);
    11301142    QToolBarAreaLayoutItem &item = this->item(path);
    11311143
     
    11331145    QToolBarAreaLayoutInfo &info = docks[path.at(0)];
    11341146    QToolBarAreaLayoutLine &line = info.lines[path.at(1)];
    1135     if (item.extraSpace != 0) {
     1147    if (item.size != pick(line.o, item.realSizeHint())) {
     1148        //the item doesn't have its default size
     1149        //so we'll give this to the next item
    11361150        int newExtraSpace = 0;
     1151        //let's iterate over the siblings of the current item that pare placed before it
     1152        //we need to find just the one before
    11371153        for (int i = path.at(2) - 1; i >= 0; --i) {
    11381154            QToolBarAreaLayoutItem &previous = line.toolBarItems[i];
    11391155            if (!previous.skip()) {
     1156                //we need to check if it has a previous element and a next one
     1157                //the previous will get its size changed
    11401158                for (int j = path.at(2) + 1; j < line.toolBarItems.count(); ++j) {
    11411159                    const QToolBarAreaLayoutItem &next = line.toolBarItems.at(j);
    11421160                    if (!next.skip()) {
    1143                         newExtraSpace = previous.extraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint());
     1161                        newExtraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint());
     1162                        previous.resize(line.o, next.pos - previous.pos);
     1163                        break;
    11441164                    }
    1145                     break;
    11461165                }
    11471166                break;
     
    11551174                QToolBarAreaLayoutItem &previous = line.toolBarItems[i];
    11561175                if (!previous.skip()) {
    1157                     previous.extraSpace = newExtraSpace;
     1176                    previous.resize(line.o, pick(line.o, previous.sizeHint()) + newExtraSpace);
    11581177                    break;
    11591178                }
     
    11621181        }
    11631182    }
    1164 
    11651183
    11661184    Q_ASSERT(!item.gap);
     
    12541272                stream << shownOrientation;
    12551273                stream << item.pos;
    1256                 //if extraSpace is 0 the item has its "normal" size, so no need to store the size (we store -1)
    1257                 stream << (item.extraSpace == 0 ? -1 : (pick(line.o, item.realSizeHint()) + item.extraSpace));
     1274                //we store the preferred size. If the use rdidn't resize the toolbars it will be -1
     1275                stream << item.preferredSize;
    12581276
    12591277                uint geom0, geom1;
     
    12841302    int lines;
    12851303    stream >> lines;
     1304        if (!testing)
     1305        testing = mainWindow->unifiedTitleAndToolBarOnMac();
    12861306
    12871307    for (int j = 0; j < lines; ++j) {
     
    12941314
    12951315        QToolBarAreaLayoutInfo &dock = docks[pos];
     1316                const bool applyingLayout = !testing && !(pos == QInternal::TopDock && mainWindow->unifiedTitleAndToolBarOnMac());
    12961317        QToolBarAreaLayoutLine line(dock.o);
    12971318
     
    13341355            }
    13351356
    1336             if (!testing) {
     1357            if (applyingLayout) {
    13371358                item.widgetItem = new QWidgetItemV2(toolBar);
    13381359                toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);
     
    13401361                toolBar->d_func()->setWindowState(floating, true, rect);
    13411362
    1342                 //if it is -1, it means we should use the default size
    1343                 item.extraSpace = (item.size == -1) ? 0 : item.size - pick(line.o, item.realSizeHint());
    1344 
    1345 
     1363                item.preferredSize = item.size;
    13461364                line.toolBarItems.append(item);
    13471365            }
    13481366        }
    13491367
    1350         if (!testing) {
     1368        if (applyingLayout) {
    13511369            dock.lines.append(line);
    13521370        }
Note: See TracChangeset for help on using the changeset viewer.