//----------------------------------------------------------------------------- void vktraceviewer_QTimelineView::scrollTo(const QModelIndex &index, ScrollHint hint/* = EnsureVisible*/) { if (!index.isValid()) { return; } QRect viewRect = viewport()->rect(); QRect itemRect = visualRect(index); if (itemRect.left() < viewRect.left()) { horizontalScrollBar()->setValue(horizontalScrollBar()->value() + itemRect.center().x() - viewport()->width()/2); } else if (itemRect.right() > viewRect.right()) { horizontalScrollBar()->setValue(horizontalScrollBar()->value() + itemRect.center().x() - viewport()->width()/2); } if (!viewRect.contains(itemRect)) { deletePixmap(); } viewport()->update(); }
void vogleditor_QTimelineView::scrollToPx(int scroll) { if (m_scroll==scroll) return; m_scroll=scroll; m_scroll=qMax(m_scroll, 0); m_scroll=qMin(m_scroll, (int)((double)m_zoom*(double)width()-width())); emit(scrollPosChanged(m_scroll)); deletePixmap(); update(); }
bool IconViewEditor::qt_invoke( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->slotOffset() ) { case 0: insertNewItem(); break; case 1: deleteCurrentItem(); break; case 2: currentItemChanged((QIconViewItem*)static_QUType_ptr.get(_o+1)); break; case 3: currentTextChanged((const QString&)static_QUType_QString.get(_o+1)); break; case 4: okClicked(); break; case 5: cancelClicked(); break; case 6: applyClicked(); break; case 7: choosePixmap(); break; case 8: deletePixmap(); break; default: return IconViewEditorBase::qt_invoke( _id, _o ); } return TRUE; }
void vogleditor_QTimelineView::resizeEvent(QResizeEvent *) { m_scrollBar->setPageStep(width()); if (m_pPixmap != NULL) { int pmHeight = m_pPixmap->height(); int pmWidth = m_pPixmap->width(); float widthPctDelta = (float)(width() - pmWidth) / (float)pmWidth; float heightPctDelta = (float)(height() - pmHeight) / (float)pmHeight; // If the resize is of a 'signficant' amount, then delete the pixmap so that it will be regenerated at the new size. if (fabs(widthPctDelta) > 0.2 || fabs(heightPctDelta) > 0.2) { deletePixmap(); } } }
bool ListBoxEditorBase::qt_invoke( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->slotOffset() ) { case 0: languageChange(); break; case 1: init(); break; case 2: destroy(); break; case 3: insertNewItem(); break; case 4: deleteCurrentItem(); break; case 5: currentItemChanged((QListBoxItem*)static_QUType_ptr.get(_o+1)); break; case 6: currentTextChanged((const QString&)static_QUType_QString.get(_o+1)); break; case 7: okClicked(); break; case 8: cancelClicked(); break; case 9: applyClicked(); break; case 10: choosePixmap(); break; case 11: deletePixmap(); break; case 12: moveItemUp(); break; case 13: moveItemDown(); break; default: return QDialog::qt_invoke( _id, _o ); } return TRUE; }
//----------------------------------------------------------------------------- void vktraceviewer_QTimelineView::scrollContentsBy(int dx, int dy) { deletePixmap(); if (dy != 0) { QPoint pos = m_mousePosition; int focusX = pos.x(); if (pos.isNull()) { // If the mouse position is NULL (ie, the mouse is not in the viewport) // zooming will happen around the center of the timeline focusX = (viewport()->width() - m_scrollBarWidth) / 2; } int x = focusX + horizontalScrollBar()->value(); float wx = (float)x / m_zoomFactor; // The zoom factor is a smoothed interpolation (based on the vertical scroll bar value and max) // between the m_durationToViewportScale (which fits the entire timeline into the viewport width) // and m_maxZoom (which is initialized to 1/1000) float zoomRatio = (float)verticalScrollBar()->value() / (float)verticalScrollBar()->maximum(); zoomRatio = 1-cos(zoomRatio*M_PI_2); float diff = m_maxZoom - m_durationToViewportScale; m_zoomFactor = m_durationToViewportScale + zoomRatio * diff; updateGeometries(); int newValue = (wx * m_zoomFactor) - focusX; horizontalScrollBar()->setValue(newValue); } viewport()->update(); // scrollDirtyRegion(dx, 0); // viewport()->scroll(dx, 0); }
//----------------------------------------------------------------------------- void vktraceviewer_QTimelineView::resizeEvent(QResizeEvent *event) { m_hashIsDirty = true; deletePixmap(); // The duration to viewport scale should allow us to map the entire timeline into the current window width. if (m_lineLength > 0) { // Calculate zoom ratio prior to the resize float ratio = m_zoomFactor / m_durationToViewportScale; // Adjust scale that fits the timeline duration to the viewport area int timelineViewportWidth = viewport()->width() - 2*m_margin - m_scrollBarWidth; m_durationToViewportScale = (float)timelineViewportWidth / u64ToFloat(m_lineLength); // Adjust the zoom factor based on the new duration to viewport scale and the previous ratio m_zoomFactor = m_durationToViewportScale * ratio; // Adjust horizontal scroll bar to maintain current view as best as possible float hRatio = (float)horizontalScrollBar()->value() / qMax(1.0f,(float)horizontalScrollBar()->maximum()); updateGeometries(); horizontalScrollBar()->setValue(hRatio * horizontalScrollBar()->maximum()); } }
//----------------------------------------------------------------------------- void vktraceviewer_QTimelineView::setModel(QAbstractItemModel* pModel) { QAbstractItemView::setModel(pModel); m_hashIsDirty = true; setItemDelegate(&m_itemDelegate); m_threadIdList.clear(); m_threadMask.clear(); m_maxItemDuration = 0; m_rawStartTime = 0; m_rawEndTime = 0; deletePixmap(); // Gather some stats from the model if (model() == NULL) { horizontalScrollBar()->setRange(0,0); verticalScrollBar()->setRange(0,0); return; } int numRows = model()->rowCount(); for (int i = 0; i < numRows; i++) { // Count number of unique thread Ids QModelIndex item = model()->index(i, vktraceviewer_QTraceFileModel::Column_ThreadId); if (item.isValid()) { uint32_t threadId = item.data().toUInt(); if (!m_threadIdList.contains(threadId)) { m_threadIdList.append(threadId); m_threadMask.insert(threadId, QVector<int>()); m_threadArea.append(QRect()); } } // Find duration of longest item item = model()->index(i, vktraceviewer_QTraceFileModel::Column_CpuDuration); if (item.isValid()) { float duration = item.data().toFloat(); if (m_maxItemDuration < duration) { m_maxItemDuration = duration; } } } // Get start time QModelIndex start = model()->index(0, vktraceviewer_QTraceFileModel::Column_BeginTime); if (start.isValid()) { m_rawStartTime = start.data().toULongLong(); } // Get end time QModelIndex end = model()->index(numRows - 1, vktraceviewer_QTraceFileModel::Column_EndTime); if (end.isValid()) { m_rawEndTime = end.data().toULongLong(); } // the duration to viewport scale should allow us to map the entire timeline into the current window width. m_lineLength = m_rawEndTime - m_rawStartTime; int initialTimelineWidth = viewport()->width() - 2*m_margin - m_scrollBarWidth; m_durationToViewportScale = (float)initialTimelineWidth / u64ToFloat(m_lineLength); m_zoomFactor = m_durationToViewportScale; verticalScrollBar()->setMaximum(1000); verticalScrollBar()->setValue(0); verticalScrollBar()->setPageStep(1); verticalScrollBar()->setSingleStep(1); }
/* * Constructs a IconViewEditorBase as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ IconViewEditorBase::IconViewEditorBase( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "IconViewEditorBase" ); setSizeGripEnabled( TRUE ); IconViewEditorBaseLayout = new QVBoxLayout( this, 11, 6, "IconViewEditorBaseLayout"); Layout6 = new QHBoxLayout( 0, 0, 6, "Layout6"); preview = new QIconView( this, "preview" ); Layout6->addWidget( preview ); Layout5 = new QVBoxLayout( 0, 0, 6, "Layout5"); itemNew = new QPushButton( this, "itemNew" ); Layout5->addWidget( itemNew ); itemDelete = new QPushButton( this, "itemDelete" ); Layout5->addWidget( itemDelete ); Vertical_Spacing1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); Layout5->addItem( Vertical_Spacing1 ); Layout6->addLayout( Layout5 ); GroupBox1 = new QGroupBox( this, "GroupBox1" ); GroupBox1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, 0, 0, GroupBox1->sizePolicy().hasHeightForWidth() ) ); GroupBox1->setColumnLayout(0, Qt::Vertical ); GroupBox1->layout()->setSpacing( 6 ); GroupBox1->layout()->setMargin( 11 ); GroupBox1Layout = new QGridLayout( GroupBox1->layout() ); GroupBox1Layout->setAlignment( Qt::AlignTop ); Label1 = new QLabel( GroupBox1, "Label1" ); GroupBox1Layout->addWidget( Label1, 0, 0 ); itemText = new QLineEdit( GroupBox1, "itemText" ); itemText->setMinimumSize( QSize( 0, 0 ) ); GroupBox1Layout->addWidget( itemText, 0, 1 ); Label2 = new QLabel( GroupBox1, "Label2" ); GroupBox1Layout->addWidget( Label2, 1, 0 ); Layout4 = new QHBoxLayout( 0, 0, 6, "Layout4"); itemPixmap = new QLabel( GroupBox1, "itemPixmap" ); Layout4->addWidget( itemPixmap ); itemDeletePixmap = new QPushButton( GroupBox1, "itemDeletePixmap" ); itemDeletePixmap->setMaximumSize( QSize( 30, 22 ) ); itemDeletePixmap->setPixmap( QPixmap::fromMimeSource( "designer_s_editcut.png" ) ); Layout4->addWidget( itemDeletePixmap ); itemChoosePixmap = new QPushButton( GroupBox1, "itemChoosePixmap" ); itemChoosePixmap->setMaximumSize( QSize( 30, 22 ) ); Layout4->addWidget( itemChoosePixmap ); GroupBox1Layout->addLayout( Layout4, 1, 1 ); Layout6->addWidget( GroupBox1 ); IconViewEditorBaseLayout->addLayout( Layout6 ); Layout1 = new QHBoxLayout( 0, 0, 6, "Layout1"); buttonHelp = new QPushButton( this, "buttonHelp" ); buttonHelp->setAutoDefault( TRUE ); Layout1->addWidget( buttonHelp ); Horizontal_Spacing2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); Layout1->addItem( Horizontal_Spacing2 ); buttonApply = new QPushButton( this, "buttonApply" ); buttonApply->setAutoDefault( TRUE ); Layout1->addWidget( buttonApply ); buttonOk = new QPushButton( this, "buttonOk" ); buttonOk->setAutoDefault( TRUE ); buttonOk->setDefault( TRUE ); Layout1->addWidget( buttonOk ); buttonCancel = new QPushButton( this, "buttonCancel" ); buttonCancel->setAutoDefault( TRUE ); Layout1->addWidget( buttonCancel ); IconViewEditorBaseLayout->addLayout( Layout1 ); languageChange(); resize( QSize(567, 321).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); // signals and slots connections connect( itemNew, SIGNAL( clicked() ), this, SLOT( insertNewItem() ) ); connect( itemDelete, SIGNAL( clicked() ), this, SLOT( deleteCurrentItem() ) ); connect( itemText, SIGNAL( textChanged( const QString & ) ), this, SLOT( currentTextChanged(const QString&) ) ); connect( buttonOk, SIGNAL( clicked() ), this, SLOT( okClicked() ) ); connect( buttonApply, SIGNAL( clicked() ), this, SLOT( applyClicked() ) ); connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( cancelClicked() ) ); connect( itemChoosePixmap, SIGNAL( clicked() ), this, SLOT( choosePixmap() ) ); connect( preview, SIGNAL( selectionChanged(QIconViewItem*) ), this, SLOT( currentItemChanged(QIconViewItem*) ) ); connect( preview, SIGNAL( currentChanged(QIconViewItem*) ), this, SLOT( currentItemChanged(QIconViewItem*) ) ); connect( itemDeletePixmap, SIGNAL( clicked() ), this, SLOT( deletePixmap() ) ); // tab order setTabOrder( buttonOk, buttonCancel ); setTabOrder( buttonCancel, preview ); setTabOrder( preview, itemNew ); setTabOrder( itemNew, itemDelete ); setTabOrder( itemDelete, itemText ); setTabOrder( itemText, itemDeletePixmap ); setTabOrder( itemDeletePixmap, itemChoosePixmap ); setTabOrder( itemChoosePixmap, buttonHelp ); setTabOrder( buttonHelp, buttonApply ); // buddies Label1->setBuddy( itemText ); Label2->setBuddy( itemChoosePixmap ); init(); }
void vogleditor_QTimelineView::paint(QPainter *painter, QPaintEvent *event) { int gap = 10; int arrowHeight = 10; int arrowTop = event->rect().height()/2-gap-arrowHeight; int arrowHalfWidth = 3; m_lineLength = event->rect().width()-2*gap; QPolygon triangle(3); triangle.setPoint(0, 0, arrowTop); triangle.setPoint(1, -arrowHalfWidth, arrowTop+arrowHeight); triangle.setPoint(2, arrowHalfWidth, arrowTop+arrowHeight); drawBaseTimeline(painter, event->rect(), gap); if (m_pModel == NULL) { return; } if (m_pModel->get_root_item() == NULL) { return; } if (m_pPixmap != NULL) { int rectHeight = event->rect().height(); int rectWidth = event->rect().width(); int pmHeight = m_pPixmap->height(); int pmWidth = m_pPixmap->width(); float widthPctDelta = (float)(rectWidth - pmWidth) / (float)pmWidth; float heightPctDelta = (float)(rectHeight - pmHeight) / (float)pmHeight; // If the resize is of a 'signficant' amount, then delete the pixmap so that it will be regenerated at the new size. if (fabs(widthPctDelta) > 0.2 || fabs(heightPctDelta) > 0.2) { deletePixmap(); } } if (m_pPixmap == NULL) { m_pPixmap = new QPixmap(event->rect().width(), event->rect().height()); QPainter pixmapPainter(m_pPixmap); drawBaseTimeline(&pixmapPainter, event->rect(), gap); // translate drawing to vertical center of rect // everything will have a small gap on the left and right sides pixmapPainter.translate(gap, event->rect().height()/2); if (m_pModel->get_root_item()->getBrush() == NULL) { m_pModel->get_root_item()->setBrush(&m_triangleBrush); } m_horizontalScale = (float)m_lineLength / (float)m_pModel->get_root_item()->getDuration(); // we don't want to draw the root item, but all of its children int numChildren = m_pModel->get_root_item()->childCount(); int height = event->rect().height()/2-2*gap; pixmapPainter.setBrush(m_triangleBrush); pixmapPainter.setPen(m_trianglePen); float minimumOffset = 0; for (int c = 0; c < numChildren; c++) { vogleditor_timelineItem* pChild = m_pModel->get_root_item()->child(c); drawTimelineItem(&pixmapPainter, pChild, height, minimumOffset); } } painter->drawPixmap(event->rect(), *m_pPixmap, m_pPixmap->rect()); // translate drawing to vertical center of rect // everything will have a small gap on the left and right sides painter->translate(gap, event->rect().height()/2); painter->setBrush(m_triangleBrush); painter->setPen(m_trianglePen); int numChildren = m_pModel->get_root_item()->childCount(); for (int c = 0; c < numChildren; c++) { vogleditor_timelineItem* pChild = m_pModel->get_root_item()->child(c); // draw current frame marker if (pChild->getFrameItem() != NULL && pChild->getFrameItem()->frameNumber() == m_curFrame) { painter->save(); painter->translate(scalePositionHorizontally(pChild->getBeginTime()), 0); painter->drawPolygon(triangle); painter->restore(); } // draw current api call marker if (pChild->getApiCallItem() != NULL && pChild->getApiCallItem()->globalCallIndex() == m_curApiCallNumber) { painter->save(); painter->translate(scalePositionHorizontally(pChild->getBeginTime()), 0); painter->drawPolygon(triangle); painter->restore(); } } }
vogleditor_QTimelineView::~vogleditor_QTimelineView() { deletePixmap(); }
/* * Constructs a ListBoxEditorBase as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ ListBoxEditorBase::ListBoxEditorBase( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "ListBoxEditorBase" ); setSizeGripEnabled( TRUE ); ListBoxEditorBaseLayout = new QGridLayout( this, 1, 1, 11, 6, "ListBoxEditorBaseLayout"); Layout1 = new QHBoxLayout( 0, 0, 6, "Layout1"); helpButton = new QPushButton( this, "helpButton" ); helpButton->setAutoDefault( TRUE ); Layout1->addWidget( helpButton ); Horizontal_Spacing2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); Layout1->addItem( Horizontal_Spacing2 ); buttonApply = new QPushButton( this, "buttonApply" ); buttonApply->setAutoDefault( TRUE ); Layout1->addWidget( buttonApply ); buttonOk = new QPushButton( this, "buttonOk" ); buttonOk->setAutoDefault( TRUE ); buttonOk->setDefault( TRUE ); Layout1->addWidget( buttonOk ); buttonCancel = new QPushButton( this, "buttonCancel" ); buttonCancel->setAutoDefault( TRUE ); Layout1->addWidget( buttonCancel ); ListBoxEditorBaseLayout->addMultiCellLayout( Layout1, 5, 5, 0, 2 ); preview = new QListBox( this, "preview" ); ListBoxEditorBaseLayout->addMultiCellWidget( preview, 0, 4, 0, 0 ); GroupBox1 = new QGroupBox( this, "GroupBox1" ); GroupBox1->setColumnLayout(0, Qt::Vertical ); GroupBox1->layout()->setSpacing( 6 ); GroupBox1->layout()->setMargin( 11 ); GroupBox1Layout = new QGridLayout( GroupBox1->layout() ); GroupBox1Layout->setAlignment( Qt::AlignTop ); Label2 = new QLabel( GroupBox1, "Label2" ); GroupBox1Layout->addWidget( Label2, 1, 0 ); itemPixmap = new QLabel( GroupBox1, "itemPixmap" ); GroupBox1Layout->addWidget( itemPixmap, 1, 1 ); itemDeletePixmap = new QPushButton( GroupBox1, "itemDeletePixmap" ); itemDeletePixmap->setMaximumSize( QSize( 30, 22 ) ); itemDeletePixmap->setPixmap( QPixmap::fromMimeSource( "designer_s_editcut.png" ) ); GroupBox1Layout->addWidget( itemDeletePixmap, 1, 2 ); itemChoosePixmap = new QPushButton( GroupBox1, "itemChoosePixmap" ); itemChoosePixmap->setMaximumSize( QSize( 30, 22 ) ); GroupBox1Layout->addWidget( itemChoosePixmap, 1, 3 ); Label1 = new QLabel( GroupBox1, "Label1" ); GroupBox1Layout->addWidget( Label1, 0, 0 ); itemText = new QLineEdit( GroupBox1, "itemText" ); itemText->setMinimumSize( QSize( 0, 0 ) ); GroupBox1Layout->addMultiCellWidget( itemText, 0, 0, 1, 3 ); ListBoxEditorBaseLayout->addMultiCellWidget( GroupBox1, 0, 4, 2, 2 ); itemNew = new QPushButton( this, "itemNew" ); ListBoxEditorBaseLayout->addWidget( itemNew, 0, 1 ); itemDelete = new QPushButton( this, "itemDelete" ); ListBoxEditorBaseLayout->addWidget( itemDelete, 1, 1 ); Vertical_Spacing1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); ListBoxEditorBaseLayout->addItem( Vertical_Spacing1, 2, 1 ); itemUp = new QPushButton( this, "itemUp" ); itemUp->setPixmap( QPixmap::fromMimeSource( "designer_s_up.png" ) ); ListBoxEditorBaseLayout->addWidget( itemUp, 3, 1 ); itemDown = new QPushButton( this, "itemDown" ); itemDown->setPixmap( QPixmap::fromMimeSource( "designer_s_down.png" ) ); ListBoxEditorBaseLayout->addWidget( itemDown, 4, 1 ); languageChange(); resize( QSize(482, 229).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); // signals and slots connections connect( itemNew, SIGNAL( clicked() ), this, SLOT( insertNewItem() ) ); connect( itemDelete, SIGNAL( clicked() ), this, SLOT( deleteCurrentItem() ) ); connect( itemText, SIGNAL( textChanged( const QString & ) ), this, SLOT( currentTextChanged(const QString&) ) ); connect( buttonOk, SIGNAL( clicked() ), this, SLOT( okClicked() ) ); connect( buttonApply, SIGNAL( clicked() ), this, SLOT( applyClicked() ) ); connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( cancelClicked() ) ); connect( itemChoosePixmap, SIGNAL( clicked() ), this, SLOT( choosePixmap() ) ); connect( itemDeletePixmap, SIGNAL( clicked() ), this, SLOT( deletePixmap() ) ); connect( itemUp, SIGNAL( clicked() ), this, SLOT( moveItemUp() ) ); connect( itemDown, SIGNAL( clicked() ), this, SLOT( moveItemDown() ) ); connect( preview, SIGNAL( selectionChanged(QListBoxItem*) ), this, SLOT( currentItemChanged(QListBoxItem*) ) ); connect( preview, SIGNAL( currentChanged( QListBoxItem * ) ), this, SLOT( currentItemChanged(QListBoxItem*) ) ); // tab order setTabOrder( buttonOk, buttonCancel ); setTabOrder( buttonCancel, preview ); setTabOrder( preview, itemNew ); setTabOrder( itemNew, itemDelete ); setTabOrder( itemDelete, itemUp ); setTabOrder( itemUp, itemDown ); setTabOrder( itemDown, itemText ); setTabOrder( itemText, itemDeletePixmap ); setTabOrder( itemDeletePixmap, itemChoosePixmap ); setTabOrder( itemChoosePixmap, helpButton ); setTabOrder( helpButton, buttonApply ); // buddies Label2->setBuddy( itemChoosePixmap ); Label1->setBuddy( itemText ); init(); }