void KateViewManager::splitViewSpace( KateViewSpace* vs, // = 0 Qt::Orientation o )// = Qt::Horizontal { // emergency: fallback to activeViewSpace, and if still invalid, abort if (!vs) vs = activeViewSpace(); if (!vs) return; // get current splitter, and abort if null QSplitter *currentSplitter = qobject_cast<QSplitter*>(vs->parentWidget()); if (!currentSplitter) return; // index where to insert new splitter/viewspace const int index = currentSplitter->indexOf( vs ); // create new viewspace KateViewSpace* vsNew = new KateViewSpace( this ); // only 1 children -> we are the root container. So simply set the orientation // and add the new view space, then correct the sizes to 50%:50% if (currentSplitter->count() == 1) { if( currentSplitter->orientation() != o ) currentSplitter->setOrientation( o ); QList<int> sizes = currentSplitter->sizes(); sizes << (sizes.first() - currentSplitter->handleWidth() ) / 2; sizes[0] = sizes[1]; currentSplitter->insertWidget( index, vsNew ); currentSplitter->setSizes( sizes ); } else { // create a new QSplitter and replace vs with the splitter. vs and newVS are // the new children of the new QSplitter QSplitter* newContainer = new QSplitter( o ); newContainer->setOpaqueResize( KGlobalSettings::opaqueResize() ); QList<int> currentSizes = currentSplitter->sizes(); newContainer->addWidget( vs ); newContainer->addWidget( vsNew ); currentSplitter->insertWidget( index, newContainer ); newContainer->show(); // fix sizes of children of old and new splitter currentSplitter->setSizes( currentSizes ); QList<int> newSizes = newContainer->sizes(); newSizes[0] = (newSizes[0] + newSizes[1] - newContainer->handleWidth()) / 2; newSizes[1] = newSizes[0]; newContainer->setSizes( newSizes ); } m_viewSpaceList.append( vsNew ); activeViewSpace()->setActive( false ); vsNew->setActive( true, true ); vsNew->show(); createView ((KTextEditor::Document*)activeView()->document()); updateViewSpaceActions (); }
void updatePosition() { int x, y; QRect widgetRect = mWidget->geometry(); int splitterWidth = mSplitter->width(); int handleWidth = mSplitter->handleWidth(); int width = q->width(); if (!isVertical()) { // FIXME: Make this configurable y = 30; if (mDirection == LTR) { if (isVisible()) { x = widgetRect.right() + handleWidth; } else { x = 0; } } else { // RTL if (isVisible()) { x = widgetRect.left() - handleWidth - width; } else { x = splitterWidth - handleWidth - width; } } } else { // FIXME x = 0; y = 0; } q->move(x, y); }
/*! * \brief Creates a manager with given \a parent. */ QToolWindowManager::QToolWindowManager(QWidget *parent) : QWidget(parent, 0) { d_ptr = new QToolWindowManagerPrivate(); d_ptr->q_ptr = this; Q_D(QToolWindowManager); d->slots_object.d = d; d->m_lastUsedArea = 0; d->m_borderSensitivity = 12; QSplitter *testSplitter = new QSplitter(); d->m_rubberBandLineWidth = testSplitter->handleWidth(); delete testSplitter; d->m_dragIndicator = new QLabel(0, Qt::ToolTip ); d->m_dragIndicator->setAttribute(Qt::WA_ShowWithoutActivating); QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); QToolWindowManagerWrapper* wrapper = new QToolWindowManagerWrapper(this); wrapper->setWindowFlags(wrapper->windowFlags() & ~Qt::Tool); mainLayout->addWidget(wrapper); connect(&(d->m_dropSuggestionSwitchTimer), SIGNAL(timeout()), &(d->slots_object), SLOT(showNextDropSuggestion())); d->m_dropSuggestionSwitchTimer.setInterval(1000); d->m_dropCurrentSuggestionIndex = 0; d->m_rectRubberBand = new QRubberBand(QRubberBand::Rectangle, this); d->m_lineRubberBand = new QRubberBand(QRubberBand::Line, this); }
void ViewWidget::createWidgets() { mSplitter = new QSplitter(this); QSplitter splitter; mSplitter->setHandleWidth(2*splitter.handleWidth()); mIG = new InspectorGadget(this); mIG->setMinimumSize(300,400); mIGPrecisionDlg = new IGPrecisionDialog(this); }
void ModelExplorer::createWidgets() { mTreeViewWidget = new TreeViewWidget(this); mClassViewWidget = new ClassViewWidget(this); mObjectExplorer = new ObjectExplorer(mIddFile,this); mStackedWidget = new QStackedWidget(this); mSplitter = new QSplitter(Qt::Vertical,this); QSplitter splitter; mSplitter->setHandleWidth(2*splitter.handleWidth()); mSplitter->addWidget(mStackedWidget); mSplitter->addWidget(mObjectExplorer); }
ToolWindowManager::ToolWindowManager(QWidget *parent) : QWidget(parent) { m_borderSensitivity = 12; QSplitter* testSplitter = new QSplitter(); m_rubberBandLineWidth = testSplitter->handleWidth(); delete testSplitter; m_dragIndicator = new QLabel(0, Qt::ToolTip ); m_dragIndicator->setAttribute(Qt::WA_ShowWithoutActivating); QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); ToolWindowManagerWrapper* wrapper = new ToolWindowManagerWrapper(this); wrapper->setWindowFlags(wrapper->windowFlags() & ~Qt::Tool); mainLayout->addWidget(wrapper); connect(&m_dropSuggestionSwitchTimer, SIGNAL(timeout()), this, SLOT(showNextDropSuggestion())); m_dropSuggestionSwitchTimer.setInterval(1000); m_dropCurrentSuggestionIndex = 0; m_allowFloatingWindow = true; m_rectRubberBand = new QRubberBand(QRubberBand::Rectangle, this); m_lineRubberBand = new QRubberBand(QRubberBand::Line, this); }
void InlineEditorWidget::createChildWidgets() { QBoxLayout* boxLayout = qobject_cast<QBoxLayout*>( layout() ); Q_ASSERT( boxLayout ); boxLayout->setSpacing( 0 ); //For now, we don't allow editing of the "head" data, just the body LayoutItemConfig config = m_layout.layoutForItem( m_index ); const int rowCount = config.rows(); if( rowCount == 0 ) return; // we have to use the same metrics as the PrettyItemDelegate or else // the widgets will change places when editing const int horizontalSpace = style()->pixelMetric( QStyle::PM_LayoutHorizontalSpacing ); const int frameHMargin = style()->pixelMetric( QStyle::PM_FocusFrameHMargin ); const int frameVMargin = style()->pixelMetric( QStyle::PM_FocusFrameVMargin ); int rowOffsetX = frameHMargin; // keep the text a little bit away from the border const int coverHeight = m_widgetHeight - frameVMargin * 2; const bool showCover = config.showCover(); if( showCover ) rowOffsetX += coverHeight + horizontalSpace/* + frameHMargin * 2*/; const int contentHeight = m_widgetHeight - frameVMargin * 2; int rowHeight = contentHeight / rowCount; const int rowWidth = m_widgetWidth - rowOffsetX - frameHMargin * 2; if( showCover ) { QModelIndex coverIndex = m_index.model()->index( m_index.row(), CoverImage ); QPixmap albumPixmap = coverIndex.data( Qt::DisplayRole ).value<QPixmap>(); if( !albumPixmap.isNull() ) { if( albumPixmap.width() > albumPixmap.height() ) albumPixmap = albumPixmap.scaledToWidth( coverHeight ); else albumPixmap = albumPixmap.scaledToHeight( coverHeight ); QLabel *coverLabel = new QLabel( this ); coverLabel->setPixmap( albumPixmap ); if( albumPixmap.width() < coverHeight ) coverLabel->setContentsMargins( ( coverHeight - albumPixmap.width() ) / 2, 0, ( coverHeight - albumPixmap.width() + 1 ) / 2, 0 ); boxLayout->setStretchFactor( coverLabel, 0 ); boxLayout->addSpacing( horizontalSpace ); } } KVBox *rowsWidget = new KVBox( this ); // --- paint all the rows for( int i = 0; i < rowCount; i++ ) { LayoutItemConfigRow row = config.row( i ); const int elementCount = row.count(); QSplitter *rowWidget = new QSplitter( rowsWidget ); connect( rowWidget, SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMoved(int,int)) ); m_splitterRowMap.insert( rowWidget, i ); //we need to do a quick pass to figure out how much space is left for auto sizing elements qreal spareSpace = 1.0; int autoSizeElemCount = 0; for( int k = 0; k < elementCount; ++k ) { spareSpace -= row.element( k ).size(); if( row.element( k ).size() < 0.001 ) autoSizeElemCount++; } const qreal spacePerAutoSizeElem = spareSpace / (qreal)autoSizeElemCount; //give left over pixels to the first rows. Widgets are doing it the same. if( i == 0 ) rowHeight++; if( i == ( contentHeight % rowCount ) ) rowHeight--; QList<int> itemWidths; int currentItemX = 0; for( int j = 0; j < elementCount; ++j ) { LayoutItemConfigRowElement element = row.element( j ); // -- calculate the size qreal size; if( element.size() < 0.001 ) size = spacePerAutoSizeElem; else size = element.size(); int itemWidth; if( j == elementCount - 1 ) // use the full with for the last item itemWidth = rowWidth - currentItemX; else itemWidth = rowWidth * size; itemWidths.append( itemWidth ); int value = element.value(); QModelIndex textIndex = m_index.model()->index( m_index.row(), value ); QString text = textIndex.data( Qt::DisplayRole ).toString(); m_orgValues.insert( value, text ); QWidget *widget = 0; //special case for painting the rating... if( value == Rating ) { int rating = textIndex.data( Qt::DisplayRole ).toInt(); KRatingWidget* ratingWidget = new KRatingWidget( 0 ); ratingWidget->setAlignment( element.alignment() ); ratingWidget->setRating( rating ); ratingWidget->setAttribute( Qt::WA_NoMousePropagation, true ); connect( ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingValueChanged()) ); m_editorRoleMap.insert( ratingWidget, value ); widget = ratingWidget; } else if( value == Divider ) { QPixmap left = The::svgHandler()->renderSvg( "divider_left", 1, rowHeight, "divider_left" ); QPixmap right = The::svgHandler()->renderSvg( "divider_right", 1, rowHeight, "divider_right" ); QPixmap dividerPixmap( 2, rowHeight ); dividerPixmap.fill( Qt::transparent ); QPainter painter( ÷rPixmap ); painter.drawPixmap( 0, 0, left ); painter.drawPixmap( 1, 0, right ); QLabel* dividerLabel = new QLabel( 0 ); dividerLabel->setPixmap( dividerPixmap ); dividerLabel->setAlignment( element.alignment() ); widget = dividerLabel; } else if( value == Moodbar ) { //we cannot ask the model for the moodbar directly as we have no //way of asking for a specific size. Instead just get the track from //the model and ask the moodbar manager ourselves. Meta::TrackPtr track = m_index.data( TrackRole ).value<Meta::TrackPtr>(); QLabel* moodbarLabel = new QLabel( 0 ); moodbarLabel->setScaledContents( true ); if( The::moodbarManager()->hasMoodbar( track ) ) { QPixmap moodbar = The::moodbarManager()->getMoodbar( track, itemWidth, rowHeight - 8 ); moodbarLabel->setPixmap( moodbar ); } widget = moodbarLabel; } //actual playlist item text is drawn here else { QLineEdit * edit = new QLineEdit( text, 0 ); edit->setFrame( false ); edit->setAlignment( element.alignment() ); edit->installEventFilter(this); // -- set font bool bold = element.bold(); bool italic = element.italic(); bool underline = element.underline(); QFont font = edit->font(); font.setBold( bold ); font.setItalic( italic ); font.setUnderline( underline ); edit->setFont( font ); connect( edit, SIGNAL(editingFinished()), this, SLOT(editValueChanged()) ); //check if this is a column that is editable. If not, make the //line edit read only. if( !isEditableColumn( static_cast<Playlist::Column>(value) ) ) { edit->setReadOnly( true ); edit->setDisabled( true ); } m_editorRoleMap.insert( edit, value ); widget = edit; } widget->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ); // or else the widget size hint influences the space it get's which messes up the layout rowWidget->addWidget( widget ); // handles are nice, but if we don't compensate for their sizes the layout // would be different from the item delegate if( j > 0 ) widget->setContentsMargins( -( ( rowWidget->handleWidth() + 1 ) / 2 ), 0, 0, 0 ); if( j < elementCount - 1 ) widget->setContentsMargins( 0, 0, -( rowWidget->handleWidth() / 2 ), 0 ); currentItemX += itemWidth; } rowWidget->setSizes( itemWidths ); } }
void KKbdAccessExtensions::showIcon() { if (!d->panel) return; QPoint p; // kdDebug() << "KKbdAccessExtensions::showIcon: topLevelWidget = " << d->panel->topLevelWidget()->name() << endl; if (::qt_cast<QSplitter*>( d->panel )) { QSplitter* splitter = dynamic_cast<QSplitter *>(d->panel); int handleNdx = d->handleNdx - 1; QValueList<int> sizes = splitter->sizes(); // kdDebug() << "KKbdAccessExtensions::showIcon: sizes = " << sizes << endl; if (splitter->orientation() == Qt::Horizontal) { d->icon->setShape(Qt::SizeHorCursor); p.setX(sizes[handleNdx] + (splitter->handleWidth() / 2)); p.setY(splitter->height() / 2); } else { d->icon->setShape(Qt::SizeVerCursor); p.setX(splitter->width() / 2); p.setY(sizes[handleNdx] + (splitter->handleWidth() / 2)); } // kdDebug() << "KKbdAccessExtensions::showIcon: p = " << p << endl; p = splitter->mapToGlobal(p); // kdDebug() << "KKbdAccessExtensions::showIcon: mapToGlobal = " << p << endl; } else { QDockWindow* dockWindow = dynamic_cast<QDockWindow *>(d->panel); p = dockWindow->pos(); if (dockWindow->area()) { // kdDebug() << "KKbdAccessExtensions::showIcon: pos = " << p << " of window = " << dockWindow->parentWidget()->name() << endl; p = dockWindow->parentWidget()->mapTo(dockWindow->topLevelWidget(), p); // kdDebug() << "KKbdAccessExtensions::showIcon: mapTo = " << p << " of window = " << dockWindow->topLevelWidget()->name() << endl; // TODO: How to get the handle width? if (d->handleNdx == 1) { d->icon->setShape(Qt::SizeHorCursor); if (dockWindow->area()->orientation() == Qt::Vertical) { if (dockWindow->area()->handlePosition() == QDockArea::Normal) // Handle is to the right of the dock window. p.setX(p.x() + dockWindow->width()); // else Handle is to the left of the dock window. } else // Handle is to the right of the dock window. p.setX(p.x() + dockWindow->width()); p.setY(p.y() + (dockWindow->height() / 2)); } else { d->icon->setShape(Qt::SizeVerCursor); p.setX(p.x() + (dockWindow->width() / 2)); if (dockWindow->area()->orientation() == Qt::Vertical) // Handle is below the dock window. p.setY(p.y() + dockWindow->height()); else { if (dockWindow->area()->handlePosition() == QDockArea::Normal) // Handle is below the dock window. p.setY(p.y() + dockWindow->height()); // else Handle is above the dock window. } } p = dockWindow->topLevelWidget()->mapToGlobal(p); } else { d->icon->setShape(Qt::SizeAllCursor); p = QPoint(dockWindow->width() / 2, dockWindow->height() / 2); p = dockWindow->mapToGlobal(p); // Undocked. Position in center of window. } } // kdDebug() << "KKbdAccessExtensions::showIcon: show(p) = " << p << endl; d->icon->show(p); }
void SplitView::split(BufferView* view, Qt::Orientation orientation) { if (view) { QSplitter* container = qobject_cast<QSplitter*>(view->parentWidget()); if (container) { int index = container->indexOf(view); BufferView* bv = 0; const int size = (orientation == Qt::Horizontal ? container->width() : container->height()) - container->handleWidth(); if (container->count() == 1 || container->orientation() == orientation) { container->setOrientation(orientation); bv = createBufferView(container, index + 1); QList<int> sizes; for (int i = 0; i < container->count(); ++i) sizes += size / container->count(); container->setSizes(sizes); } else if (index != -1) { QList<int> sizes = container->sizes(); QSplitter* splitter = wrap(view, orientation); if (splitter) { container->setSizes(sizes); bv = createBufferView(splitter); splitter->setSizes(QList<int>() << size/2 << size/2); } } if (bv) { bv->setBuffer(view->buffer()); emit viewAdded(bv); } } } }