From: werner s. <wsc...@us...> - 2005-11-01 10:00:42
|
Update of /cvsroot/lmuse/muse/muse/arranger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15665/muse/arranger Modified Files: arranger.cpp arranger.h tlwlayout.cpp tlwlayout.h Log Message: fix geometry management of arranger track list Index: tlwlayout.h =================================================================== RCS file: /cvsroot/lmuse/muse/muse/arranger/tlwlayout.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tlwlayout.h 22 Sep 2005 20:11:50 -0000 1.3 --- tlwlayout.h 1 Nov 2005 10:00:29 -0000 1.4 *************** *** 10,27 **** #define __TLWLAYOUT_H__ - #if 0 - //--------------------------------------------------------- - // TLItem - //--------------------------------------------------------- - - class TLItem : public QWidgetItem { - int _groupId; - - public: - TLItem(QWidget* w, int gid) : QWidgetItem(w), _groupId(gid) {} - int groupId() const { return _groupId; } - }; - #endif - //--------------------------------------------------------- // TLWidgetLayout --- 10,13 ---- *************** *** 36,50 **** TLWidgetLayout(QWidget* parent); TLWidgetLayout(); ! ~TLWidgetLayout(); ! void addItem(QLayoutItem*); ! Qt::Orientations expandingDirections() const; ! bool hasHeightForWidth() const; ! int heightForWidth(int) const; ! int count() const; QSize minimumSize() const; void setGeometry(const QRect &rect); QSize sizeHint() const; ! QLayoutItem *itemAt(int index) const; QLayoutItem *takeAt(int index); void clear(); --- 22,35 ---- TLWidgetLayout(QWidget* parent); TLWidgetLayout(); ! ~TLWidgetLayout() { clear(); } ! void addItem(QLayoutItem* item) { itemList.append(item); } ! Qt::Orientations expandingDirections() const { return 0; } ! bool hasHeightForWidth() const { return false; } ! int count() const { return itemList.size(); } QSize minimumSize() const; void setGeometry(const QRect &rect); QSize sizeHint() const; ! QLayoutItem *itemAt(int index) const { return itemList.value(index); } QLayoutItem *takeAt(int index); void clear(); Index: arranger.h =================================================================== RCS file: /cvsroot/lmuse/muse/muse/arranger/arranger.h,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** arranger.h 24 Oct 2005 12:31:56 -0000 1.50 --- arranger.h 1 Nov 2005 10:00:29 -0000 1.51 *************** *** 55,60 **** public: ! TLayout(QWidget* parent); ! TLayout(); ~TLayout() { deleteAllItems(); } --- 55,59 ---- public: ! TLayout() {} ~TLayout() { deleteAllItems(); } *************** *** 63,67 **** Qt::Orientations expandingDirections() const { return 0; } bool hasHeightForWidth() const { return false; } ! int count() const { return itemList.size(); } void setGeometry(const QRect &rect); QSize sizeHint() const { return ((QWidget*)parent())->size(); } --- 62,90 ---- Qt::Orientations expandingDirections() const { return 0; } bool hasHeightForWidth() const { return false; } ! int count() const { return itemList.size(); } ! void setGeometry(const QRect &rect); ! QSize sizeHint() const { return ((QWidget*)parent())->size(); } ! QLayoutItem *itemAt(int index) const { return itemList.value(index); } ! QLayoutItem *takeAt(int idx) { ! return idx >= 0 && idx < itemList.size() ? itemList.takeAt(idx) : 0; ! } ! }; ! ! //--------------------------------------------------------- ! // TlsvLayout ! //--------------------------------------------------------- ! ! class TlsvLayout : public QLayout { ! QList<QLayoutItem*> itemList; ! ! public: ! TlsvLayout() {} ! ~TlsvLayout() { deleteAllItems(); } ! ! void addItem(QLayoutItem* item); ! void insertWidget(int index, QWidget* item); ! Qt::Orientations expandingDirections() const { return 0; } ! bool hasHeightForWidth() const { return false; } ! int count() const { return itemList.size(); } void setGeometry(const QRect &rect); QSize sizeHint() const { return ((QWidget*)parent())->size(); } Index: tlwlayout.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/arranger/tlwlayout.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** tlwlayout.cpp 18 Oct 2005 19:41:41 -0000 1.10 --- tlwlayout.cpp 1 Nov 2005 10:00:29 -0000 1.11 *************** *** 4,8 **** // $Id$ // ! // (C) Copyright 2004 Werner Schweer (ws...@se...) //========================================================= --- 4,8 ---- // $Id$ // ! // (C) Copyright 2005 Werner Schweer (ws...@se...) //========================================================= *************** *** 10,13 **** --- 10,17 ---- #include "arranger.h" + //--------------------------------------------------------- + // TLWidgetLayout + //--------------------------------------------------------- + TLWidgetLayout::TLWidgetLayout(QWidget *parent) : QLayout(parent) *************** *** 23,96 **** } ! TLWidgetLayout::~TLWidgetLayout() ! { ! QLayoutItem *item; ! while ((item = takeAt(0))) ! delete item; ! } ! ! void TLWidgetLayout::addItem(QLayoutItem *item) ! { ! itemList.append(item); ! } ! ! int TLWidgetLayout::count() const ! { ! return itemList.size(); ! } ! ! QLayoutItem *TLWidgetLayout::itemAt(int index) const ! { ! return itemList.value(index); ! } QLayoutItem *TLWidgetLayout::takeAt(int index) { ! if (index >= 0 && index < itemList.size()) return itemList.takeAt(index); ! else return 0; } ! Qt::Orientations TLWidgetLayout::expandingDirections() const ! { ! return 0; ! } ! ! bool TLWidgetLayout::hasHeightForWidth() const ! { ! return false; ! } ! ! int TLWidgetLayout::heightForWidth(int width) const ! { ! int height = doLayout(QRect(0, 0, width, 0), true); ! return height; ! } void TLWidgetLayout::setGeometry(const QRect &rect) { ! QLayout::setGeometry(rect); ! doLayout(rect, false); ! } ! ! QSize TLWidgetLayout::sizeHint() const ! { ! return minimumSize(); ! } ! ! QSize TLWidgetLayout::minimumSize() const ! { ! QSize size; ! QLayoutItem *item; ! foreach (item, itemList) ! size = size.expandedTo(item->minimumSize()); ! ! size += QSize(2*margin(), 2*margin()); ! return size; ! } - int TLWidgetLayout::doLayout(const QRect &rect, bool testOnly) const - { const int labelWidth = 50; int x = rect.x() + labelWidth; --- 27,51 ---- } ! //--------------------------------------------------------- ! // takeAt ! //--------------------------------------------------------- QLayoutItem *TLWidgetLayout::takeAt(int index) { ! if (index >= 0 && index < itemList.size()) return itemList.takeAt(index); ! else return 0; } ! //--------------------------------------------------------- ! // setGeometry ! //--------------------------------------------------------- void TLWidgetLayout::setGeometry(const QRect &rect) { ! // printf("TLWidgetLayout %d %d %d %d\n", rect.x(), rect.y(), rect.width(), rect.height()); ! // QLayout::setGeometry(rect); const int labelWidth = 50; int x = rect.x() + labelWidth; *************** *** 101,199 **** if (n > 0) { QLayoutItem *item = itemList.at(0); ! if (item && !testOnly) item->setGeometry(QRect(QPoint(rect.x(), y), QSize(labelWidth, rect.height()))); for (int i = 1; i < n; ++i) { QLayoutItem *item = itemList.at(i); ! int nextX = x + item->sizeHint().width() + spacing(); if (nextX - spacing() > rect.right() && lineHeight > 0) { x = rect.x() + labelWidth; ! y = y + lineHeight + spacing(); ! nextX = x + item->sizeHint().width() + spacing(); lineHeight = 0; } ! ! if (!testOnly) ! item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); ! x = nextX; ! lineHeight = qMax(lineHeight, item->sizeHint().height()); ! } ! } ! return y + lineHeight - rect.y(); ! } ! ! //--------------------------------------------------------- ! // clear ! //--------------------------------------------------------- ! ! void TLWidgetLayout::clear() ! { ! int n = itemList.size(); ! for (int i = 0; i < n; ++i) { ! // TLItem* item = itemList.at(i); ! QLayoutItem* item = itemList.at(i); ! QWidget* widget = item->widget(); ! if (widget) { ! widget->close(false); ! widget->deleteLater(); } - else - printf("no WIDGET\n"); - } - itemList.clear(); - } - - #if 0 - //--------------------------------------------------------- - // TLWidgetLayoutIterator - //--------------------------------------------------------- - - class TLWidgetLayoutIterator : public QLayoutIterator - { - std::vector<TLItem*>::iterator i; - std::vector<TLItem*>* list; - - public: - TLWidgetLayoutIterator(std::vector<TLItem*>* l) - : list(l) { - i = list->begin(); - } - - QLayoutItem* current() { - return i == list->end() ? 0 : *i; - } - QLayoutItem* next() { - if (i == list->end()) - return 0; - ++i; - return current(); - } - - QLayoutItem* takeCurrent() { - if (i == list->end()) - return 0; - TLItem* item = *i; - list->erase(i); - return item; } - }; - - //--------------------------------------------------------- - // addItem - //--------------------------------------------------------- - - void TLWidgetLayout::addItem(QLayoutItem*) - { - printf("does not work\n"); - } - - //--------------------------------------------------------- - // add - //--------------------------------------------------------- - - void TLWidgetLayout::add(QWidget* w, int groupId) - { - TLItem* item = new TLItem(w, groupId); - list.push_back(item); } --- 56,77 ---- if (n > 0) { QLayoutItem *item = itemList.at(0); ! if (item) item->setGeometry(QRect(QPoint(rect.x(), y), QSize(labelWidth, rect.height()))); for (int i = 1; i < n; ++i) { QLayoutItem *item = itemList.at(i); ! QSize size(item->sizeHint()); ! ! int nextX = x + size.width() + spacing(); if (nextX - spacing() > rect.right() && lineHeight > 0) { x = rect.x() + labelWidth; ! y += lineHeight + spacing(); ! nextX = x + size.width() + spacing(); lineHeight = 0; } ! item->setGeometry(QRect(QPoint(x, y), size)); x = nextX; ! lineHeight = qMax(lineHeight, size.height()); } } } *************** *** 204,208 **** QSize TLWidgetLayout::sizeHint() const { ! return QSize(0, TRACK_ROW_HEIGHT); } --- 82,86 ---- QSize TLWidgetLayout::sizeHint() const { ! return minimumSize(); } *************** *** 213,322 **** QSize TLWidgetLayout::minimumSize() const { ! return QSize(0, 0); ! } ! ! //--------------------------------------------------------- ! // iterator ! //--------------------------------------------------------- ! ! QLayoutIterator TLWidgetLayout::iterator() ! { ! // return QLayoutIterator; //TD (new TLWidgetLayoutIterator(&list)); ! } ! ! //--------------------------------------------------------- ! // setGeometry ! //--------------------------------------------------------- ! ! void TLWidgetLayout::setGeometry(const QRect& rect) ! { ! static const int groupDistance = 0; ! static const int itemDistance = 2; ! static const int rowDist = 2; ! ! int labelWidth = 50; ! QLayout::setGeometry(rect); ! ! if (list.empty()) ! return; ! ! int x = rect.x(); ! if (strcmp(name(), "tlswidget") == 0) { ! x += 10; ! labelWidth -= 10; ! } ! int h = rect.height(); ! int y = rect.y(); ! int x2 = rect.width() + x; ! int y2 = rect.height() + y; ! ! std::vector<TLItem*>::iterator it = list.begin(); ! TLItem* item = *it++; ! item->setGeometry(QRect(x, y, labelWidth, h)); ! x += labelWidth + itemDistance; ! item = *it++; // track name ! item->setGeometry(QRect(x, y, x2-x, TRACK_ROW_HEIGHT)); ! y += TRACK_ROW_HEIGHT; ! ! ! for (; it != list.end();) { ! // ! // how many elemnts fit on row? ! // ! int xx = x; ! std::vector<TLItem*>::iterator it2(it); ! while (it2 != list.end()) { ! int curId = (*it2)->groupId(); ! std::vector<TLItem*>::iterator it3(it2); ! for (; it3 != list.end(); ++it3) { ! TLItem* item = *it3; ! if (item->groupId() != curId) ! break; ! QSize s = item->minimumSize(); ! xx += s.width() + itemDistance; ! } ! xx -= itemDistance; ! if (xx > x2) ! break; ! it2 = it3; ! xx += groupDistance; ! } ! // ! // place row ! // ! int curId = (*it)->groupId(); ! xx = x; ! for (; it != it2; ++it) { ! TLItem* item = *it; ! if (item->groupId() != curId) { ! xx += groupDistance - itemDistance; ! curId = item->groupId(); ! } ! QSize s = item->minimumSize(); ! int w = s.width(); ! /* TD if ((it+1 == it2) && (item->expanding() & QSizePolicy::Horizontally)) { ! w = x2 - xx; ! if (item->sizeHint().width() < w) ! w = item->sizeHint().width(); ! } ! */ ! item->setGeometry(QRect(xx, y, w, TRACK_ROW_HEIGHT-rowDist)); ! xx += w + itemDistance; ! } ! // ! // next row ! // ! y += TRACK_ROW_HEIGHT; ! if (y + TRACK_ROW_HEIGHT > y2) ! break; ! } ! for (; it != list.end(); ++it) { ! TLItem* item = *it; ! if (item->widget()) { ! // hide widget ! item->setGeometry(QRect(10000, 10000, 0, 0)); ! } ! } } --- 91,101 ---- QSize TLWidgetLayout::minimumSize() const { ! QSize size; ! QLayoutItem *item; ! foreach (item, itemList) ! size = size.expandedTo(item->minimumSize()); ! size += QSize(2*margin(), 2*margin()); ! return size; } *************** *** 327,369 **** void TLWidgetLayout::clear() { - #if 0 - std::vector<TLItem*>::iterator it = list.begin(); - for (; it != list.end(); ++it) { - TLItem* item = *it; - QWidget* widget = item->widget(); - if (widget) { - widget->close(false); - widget->deleteLater(); - } - else - printf("no WIDGET\n"); - } - list.clear(); - #endif - - QLayoutItem *item; - while ((item = takeAt(0))) - delete item; - list.clear(); - } - - //--------------------------------------------------------- - // TLWidgetLayout - //--------------------------------------------------------- - - TLWidgetLayout::TLWidgetLayout(QWidget* parent) - : QLayout(parent, 0, 0) - { - setResizeMode(FreeResize); - } - - //--------------------------------------------------------- - // ~TLWidgetLayout - //--------------------------------------------------------- - - TLWidgetLayout::~TLWidgetLayout() - { deleteAllItems(); } - #endif --- 106,110 ---- Index: arranger.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/muse/arranger/arranger.cpp,v retrieving revision 1.111 retrieving revision 1.112 diff -C2 -d -r1.111 -r1.112 *** arranger.cpp 27 Oct 2005 17:27:19 -0000 1.111 --- arranger.cpp 1 Nov 2005 10:00:29 -0000 1.112 *************** *** 70,90 **** //--------------------------------------------------------- - // TLayout - //--------------------------------------------------------- - - TLayout::TLayout(QWidget *parent) - : QLayout(parent) - { - setMargin(0); - setSpacing(0); - } - - TLayout::TLayout() - { - setMargin(0); - setSpacing(0); - } - - //--------------------------------------------------------- // insertWidget //--------------------------------------------------------- --- 70,73 ---- *************** *** 112,124 **** //--------------------------------------------------------- ! void TLayout::setGeometry(const QRect&) { ! int y = 3; // margin int n = itemList.size(); for (int i = 0; i < n; ++i) { QLayoutItem *item = itemList.at(i); QWidget* w = item->widget(); int h = w->height(); ! w->setGeometry(0, y, ((QWidget*)parent())->width(), h); y += h; } --- 95,109 ---- //--------------------------------------------------------- ! void TLayout::setGeometry(const QRect& r) { ! // printf("TLayout: %d %d %d %d\n", r.x(), r.y(), r.width(), r.height()); ! int y = r.y() + 3; int n = itemList.size(); + int width = r.width(); // ((QWidget*)parent())->width(); for (int i = 0; i < n; ++i) { QLayoutItem *item = itemList.at(i); QWidget* w = item->widget(); int h = w->height(); ! w->setGeometry(0, y, width, h); y += h; } *************** *** 126,129 **** --- 111,147 ---- //--------------------------------------------------------- + // insertWidget + //--------------------------------------------------------- + + void TlsvLayout::insertWidget(int index, QWidget* item) + { + if (item->parent() == 0) + item->setParent((QWidget*)parent()); + itemList.insert(index, new QWidgetItem(item)); + update(); + } + + //--------------------------------------------------------- + // addItem + //--------------------------------------------------------- + + void TlsvLayout::addItem(QLayoutItem* item) + { + itemList.append(item); + update(); + } + + //--------------------------------------------------------- + // setGeometry + //--------------------------------------------------------- + + void TlsvLayout::setGeometry(const QRect& r) + { + QLayoutItem *item = itemList.at(0); + QWidget* w = item->widget(); + w->setGeometry(0, 0, r.width(), w->height()); + } + + //--------------------------------------------------------- // newAddTrackMenu //--------------------------------------------------------- *************** *** 171,179 **** trackInfoVisible = false; mixerStripVisible = false; ! QGridLayout* centralGrid = new QGridLayout(this, 1, 1, 0, 0, "centralGrid"); ! centralGrid->setName("centralGrid"); split = new Splitter(Qt::Horizontal); - split->setOpaqueResize(true); split->setChildrenCollapsible(true); --- 189,198 ---- trackInfoVisible = false; mixerStripVisible = false; ! QLayout* ml = new QHBoxLayout; ! ml->setSpacing(0); ! ml->setMargin(1); ! setLayout(ml); split = new Splitter(Qt::Horizontal); split->setOpaqueResize(true); split->setChildrenCollapsible(true); *************** *** 200,212 **** tlsv = new QWidget; tlsv->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); ! QVBoxLayout* tlsvLayout = new QVBoxLayout; ! tlsvLayout->setMargin(0); ! tlsvLayout->setSpacing(0); ! tlsvLayout->setSizeConstraint(QLayout::SetNoConstraint); ! tlsv->setLayout(tlsvLayout); ! trackList = new TrackListWidget; ! tlsvLayout->addWidget(trackList); ! tlsvLayout->addStretch(100); tl = new TLayout; trackList->setLayout(tl); --- 219,225 ---- tlsv = new QWidget; tlsv->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); ! tlsv->setLayout(new TlsvLayout); trackList = new TrackListWidget; ! tlsv->layout()->addWidget(trackList); tl = new TLayout; trackList->setLayout(tl); *************** *** 316,320 **** song, SLOT(changePart(Part*,unsigned,unsigned))); ! centralGrid->addWidget(split, 0, 0); connect(muse, SIGNAL(configChanged()), SLOT(updateConfiguration())); --- 329,334 ---- song, SLOT(changePart(Part*,unsigned,unsigned))); ! // centralLayout->addWidget(split); ! layout()->addWidget(split); connect(muse, SIGNAL(configChanged()), SLOT(updateConfiguration())); *************** *** 332,336 **** void Arranger::setTLViewPos(int /*x*/, int y) { ! int dx = 0; // x + trackList->x(); int dy = y + trackList->y(); tlsv->scroll(-dx, -dy); --- 346,350 ---- void Arranger::setTLViewPos(int /*x*/, int y) { ! int dx = 0; int dy = y + trackList->y(); tlsv->scroll(-dx, -dy); *************** *** 398,403 **** connect(tw, SIGNAL(moveTrack(Track*,Track*)), SLOT(moveTrack(Track*,Track*))); connect(this, SIGNAL(configChanged()), tw, SLOT(configChanged())); ! connect(l1, SIGNAL(drag(int, int)), SLOT(drag(int,int))); ! connect(l1, SIGNAL(startDrag(int)), SLOT(startDrag(int))); connect(t, SIGNAL(partsChanged()), canvas->widget(), SLOT(update())); --- 412,417 ---- connect(tw, SIGNAL(moveTrack(Track*,Track*)), SLOT(moveTrack(Track*,Track*))); connect(this, SIGNAL(configChanged()), tw, SLOT(configChanged())); ! connect(l1, SIGNAL(drag(int, int)), SLOT(drag(int,int))); ! connect(l1, SIGNAL(startDrag(int)), SLOT(startDrag(int))); connect(t, SIGNAL(partsChanged()), canvas->widget(), SLOT(update())); |