/** Intializes the PartResizerWidget @param d the Device the Partition is on @param p the Partition to show and/or resize @param minFirst the minimum value for the first sector @param maxLast the maximum value for the last sector */ void PartResizerWidget::init(Device& d, Partition& p, qint64 minFirst, qint64 maxLast, bool read_only, bool move_allowed) { setDevice(d); setPartition(p); setMinimumFirstSector(minFirst); setMaximumLastSector(maxLast); setReadOnly(read_only); setMoveAllowed(move_allowed); setMinimumLength(qMax(partition().sectorsUsed(), partition().minimumSectors())); setMaximumLength(qMin(totalSectors(), partition().maximumSectors())); // set margins to accommodate to top/bottom button asymmetric layouts QStyleOptionButton bOpt; bOpt.initFrom(this); QRect buttonRect(style()->subElementRect(QStyle::SE_PushButtonContents, &bOpt)); int asym = (rect().bottom() - buttonRect.bottom()) - (buttonRect.top() - rect().top()); if (asym > 0) setContentsMargins(0, asym, 0, 0); else setContentsMargins(0, 0, 0, asym); if (!readOnly()) { QPixmap pixmap(handleWidth(), handleHeight()); pixmap.fill(Qt::transparent); QPainter p(&pixmap); QStyleOption opt; opt.state |= QStyle::State_Horizontal; opt.rect = pixmap.rect().adjusted(0, 2, 0, -2); style()->drawControl(QStyle::CE_Splitter, &opt, &p, this); leftHandle().setPixmap(pixmap); rightHandle().setPixmap(pixmap); leftHandle().setFixedSize(handleWidth(), handleHeight()); rightHandle().setFixedSize(handleWidth(), handleHeight()); } delete m_PartWidget; m_PartWidget = new PartWidget(this, &partition()); if (!readOnly()) { leftHandle().setCursor(Qt::SizeHorCursor); rightHandle().setCursor(Qt::SizeHorCursor); } if (moveAllowed()) partWidget().setCursor(Qt::SizeAllCursor); partWidget().setToolTip(QString()); updatePositions(); }
void QSplitter::setRubberBand(int pos) { Q_D(QSplitter); if (pos < 0) { if (d->rubberBand) QTimer::singleShot(0, d->rubberBand, SLOT(deleteLater())); return; } QRect r = contentsRect(); const int rBord = 3; // customizable? int hw = handleWidth(); if (!d->rubberBand) { d->rubberBand = new QRubberBand(QRubberBand::Line); // For accessibility to identify this special widget. d->rubberBand->setObjectName(QLatin1String("qt_rubberband")); } if (d->orient == Qt::Horizontal) d->rubberBand->setGeometry(QRect(QPoint(pos + hw / 2 - rBord, r.y()), QSize(2 * rBord, r.height())).translated(mapToGlobal(QPoint()))); else d->rubberBand->setGeometry(QRect(QPoint(r.x(), pos + hw / 2 - rBord), QSize(r.width(), 2 * rBord)).translated(mapToGlobal(QPoint()))); if (!d->rubberBand->isVisible()) d->rubberBand->show(); }
void TerminalSplitter::recursiveCleanup() { /* Clean away empty splitters after a terminal was removed. */ QObjectList* list = queryList("TerminalSplitter", 0, false, false); QObjectListIt it(*list); QObject *obj; while ((obj = it.current()) != 0) { ++it; TerminalSplitter* splitter = static_cast<TerminalSplitter*>(obj); splitter->recursiveCleanup(); } if (count() == 0) deleteLater(); else { // Update minimum sizes. if (orientation() == TerminalSplitter::Horizontal) { int minimumWidth = (terminalCount() > 1) ? terminalCount()*150+handleWidth() : terminalCount()*150; setMinimumSize(QSize(minimumWidth, minimumHeight())); } else if (orientation() == TerminalSplitter::Vertical) { int minimumHeight = (terminalCount() > 1) ? terminalCount()*70+handleWidth() : terminalCount()*70; setMinimumSize(QSize(minimumWidth(), minimumHeight)); } } }
int QSplitter::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QFrame::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 1) qt_static_metacall(this, _c, _id, _a); _id -= 1; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< Qt::Orientation*>(_v) = orientation(); break; case 1: *reinterpret_cast< bool*>(_v) = opaqueResize(); break; case 2: *reinterpret_cast< int*>(_v) = handleWidth(); break; case 3: *reinterpret_cast< bool*>(_v) = childrenCollapsible(); break; } _id -= 4; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setOrientation(*reinterpret_cast< Qt::Orientation*>(_v)); break; case 1: setOpaqueResize(*reinterpret_cast< bool*>(_v)); break; case 2: setHandleWidth(*reinterpret_cast< int*>(_v)); break; case 3: setChildrenCollapsible(*reinterpret_cast< bool*>(_v)); break; } _id -= 4; } else if (_c == QMetaObject::ResetProperty) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 4; } #endif // QT_NO_PROPERTIES return _id; }
void PartResizerWidget::mouseMoveEvent(QMouseEvent* event) { int x = event->pos().x() - m_Hotspot; if (draggedWidget() == &leftHandle()) { const qint64 newFirstSector = qMax(minimumFirstSector() + x * sectorsPerPixel(), 0LL); updateFirstSector(newFirstSector); } else if (draggedWidget() == &rightHandle()) { const qint64 newLastSector = qMin(minimumFirstSector() + (x - rightHandle().width()) * sectorsPerPixel(), maximumLastSector()); updateLastSector(newLastSector); } else if (draggedWidget() == &partWidget() && moveAllowed()) { const qint64 newFirstSector = qMax(minimumFirstSector() + (x - handleWidth()) * sectorsPerPixel(), 0LL); movePartition(newFirstSector); } }
/*! Saves the state of the splitter's layout. Typically this is used in conjunction with QSettings to remember the size for a future session. A version number is stored as part of the data. Here is an example: \snippet doc/src/snippets/splitter/splitter.cpp 1 \sa restoreState() */ QByteArray QSplitter::saveState() const { Q_D(const QSplitter); int version = 0; QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); stream << qint32(SplitterMagic); stream << qint32(version); QList<int> list; for (int i = 0; i < d->list.size(); ++i) { QSplitterLayoutStruct *s = d->list.at(i); list.append(s->sizer); } stream << list; stream << childrenCollapsible(); stream << qint32(handleWidth()); stream << opaqueResize(); stream << qint32(orientation()); return data; }
void QSplitter::setRubberBand(int pos) { Q_D(QSplitter); if (pos < 0) { if (d->rubberBand) d->rubberBand->deleteLater(); return; } QRect r = contentsRect(); const int rBord = 3; // customizable? int hw = handleWidth(); if (!d->rubberBand) { QBoolBlocker b(d->blockChildAdd); d->rubberBand = new QRubberBand(QRubberBand::Line, this); // For accessibility to identify this special widget. d->rubberBand->setObjectName(QLatin1String("qt_rubberband")); } const QRect newGeom = d->orient == Qt::Horizontal ? QRect(QPoint(pos + hw / 2 - rBord, r.y()), QSize(2 * rBord, r.height())) : QRect(QPoint(r.x(), pos + hw / 2 - rBord), QSize(r.width(), 2 * rBord)); d->rubberBand->setGeometry(newGeom); d->rubberBand->show(); }
int PartResizerWidget::partWidgetStart() const { return handleWidth() + (partition().firstSector() - minimumFirstSector()) / sectorsPerPixel(); }
qint64 PartResizerWidget::sectorsPerPixel() const { return totalSectors() / (width() - 2 * handleWidth()); }